Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 注册映射时缺少类型映射配置或不支持映射_C#_Automapper - Fatal编程技术网

C# 注册映射时缺少类型映射配置或不支持映射

C# 注册映射时缺少类型映射配置或不支持映射,c#,automapper,C#,Automapper,我一直在阅读关于这个问题的类似问题,但我似乎不理解解决方案 我试图将我的实体映射到我的视图模型,我注意到它对我的一些实体失败了。例如: 实体 public class Warehouse : EntityBase { [Index(IsUnique = true)] [MaxLength(20)] [Required] public string Code { get; set; } [Required] public string Name {

我一直在阅读关于这个问题的类似问题,但我似乎不理解解决方案

我试图将我的实体映射到我的视图模型,我注意到它对我的一些实体失败了。例如:

实体

public class Warehouse : EntityBase
{
    [Index(IsUnique = true)]
    [MaxLength(20)]
    [Required]
    public string Code { get; set; }
    [Required]
    public string Name { get; set; }
    public string Description { get; set; }
    public int AddressId { get; set; }

    [ForeignKey("AddressId")]
    public virtual Address Address { get; set; }
    public virtual ICollection<Location> Locations { get; set; }

    public Warehouse()
    {

    }
}

public abstract class EntityBase : IConcurrencyEnabled
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int Id { get; set; }
    [Timestamp]
    public byte[] RowVersion { get; set; }
    public string CreatedBy { get; set; }
    public DateTime DateCreated { get; set; }
}  

感谢您的帮助。TIA.

关键是信息的这一部分,指向开头:

缺少类型映射配置或不支持的映射

映射类型:WarehouseVM->Warehouse

您需要创建映射以支持此操作:

cfg.CreateMap<WarehouseVM , Warehouse>();
cfg.CreateMap();

关键是消息开头的这一部分:

缺少类型映射配置或不支持的映射

映射类型:WarehouseVM->Warehouse

您需要创建映射以支持此操作:

cfg.CreateMap<WarehouseVM , Warehouse>();
cfg.CreateMap();

异常会告诉您出了什么问题:

缺少类型映射配置或不支持的映射

缺少的映射是:

仓库WMAS.Shared.Models.WarehouseVM->WMAS.Data.Entities.Warehouse


检查您的
MapperConfig
我看不到从
WarehousVM
Warehouse
的映射。添加映射应该可以解决此问题。

异常会告诉您出了什么问题:

缺少类型映射配置或不支持的映射

缺少的映射是:

仓库WMAS.Shared.Models.WarehouseVM->WMAS.Data.Entities.Warehouse


检查您的
MapperConfig
我看不到从
WarehousVM
Warehouse
的映射。添加映射应该可以解决问题。

读了答案后,我觉得自己好笨。一定是压力太大,没注意到那个。我不确定哪一个答案是第一个,你的还是@AaronLS,但我会在假期后的4天内回到这个问题上来,并进行测试。读完答案后,我觉得自己太傻了。一定是压力太大,没注意到那个。我不确定哪一个答案是第一个,你的还是@AaronLS,但我会在假期后的4天内回到这个问题上并进行测试。根据谁先回答,将此标记为正确答案。根据谁先回答,将此标记为正确答案。
WMAS.Data.Entities.Warehouse warehouse = viewModel.Item.Map<WarehouseVM, WMAS.Data.Entities.Warehouse>();
public class MapperConfig
{
    public static MapperConfiguration MapperCfg { get; private set; }
    public static IMapper Mapper { get; private set; }

    public static void RegisterMappings()
    {
        MapperCfg = new MapperConfiguration(cfg =>
        {
            cfg.AllowNullCollections = true;
            cfg.AllowNullDestinationValues = true;
            cfg.CreateMap<Address, AddressVM>().ReverseMap();
            cfg.CreateMap<ApplicationUserDepartment, ApplicationUserDepartmentVM>().ReverseMap();
            cfg.CreateMap<BasicInfo, BasicInfoVM>().ReverseMap();
            cfg.CreateMap<CityMunicipality, CityMunicipalityVM>().ReverseMap();
            cfg.CreateMap<Company, CompanyVM>().ReverseMap();
            cfg.CreateMap<Country, CountryVM>().ReverseMap();
            cfg.CreateMap<Customer, CustomerVM>().ReverseMap();
            cfg.CreateMap<DeliverySlip, DeliverySlipVM>().ReverseMap();
            cfg.CreateMap<DeliverySlipItem, DeliverySlipItemVM>().ReverseMap();
            cfg.CreateMap<Department, DepartmentVM>().ReverseMap();
            cfg.CreateMap<Image, ImageVM>().ReverseMap();
            cfg.CreateMap<InventBatch, InventBatchVM>().ReverseMap();
            cfg.CreateMap<InventLedger, InventLedgerVM>().ReverseMap();
            cfg.CreateMap<Item, ItemVM>().ReverseMap();
            cfg.CreateMap<ItemCategory, ItemCategoryVM>().ReverseMap();
            cfg.CreateMap<Location, LocationVM>().ReverseMap();
            cfg.CreateMap<Module, ModuleVM>().ReverseMap();
            cfg.CreateMap<Province, ProvinceVM>().ReverseMap();
            cfg.CreateMap<PurchaseOrder, PurchaseOrderVM>().ReverseMap();
            cfg.CreateMap<PurchaseOrderItem, PurchaseOrderItemVM>().ReverseMap();
            cfg.CreateMap<Region, RegionVM>().ReverseMap();
            cfg.CreateMap<SalesInvoice, SalesInvoiceVM>().ReverseMap();
            cfg.CreateMap<SalesInvoiceItem, SalesInvoiceItemVM>().ReverseMap();
            cfg.CreateMap<SalesInvoicePayment, SalesInvoicePaymentVM>().ReverseMap();
            cfg.CreateMap<Submodule, SubmoduleVM>().ReverseMap();
            cfg.CreateMap<SysConfig, SysConfigVM>().ReverseMap();
        });

        Mapper = MapperCfg.CreateMapper();
    }
}
cfg.CreateMap<WarehouseVM , Warehouse>();