c# - “AutoMapper.AutoMapperMappingException”发生在 AutoMapper.dll 中,但未在用户代码中处理

标签 c# automapper

_quatationRepository = new QuatationRepository();
IList<Quatation> quatationObj = _quatationRepository.GetAll(quatation => quatation.IsDeleted == 0);
IList<QuatationModel> quatationModelObj = new List<QuatationModel>();

AutoMapper.Mapper.CreateMap<Quatation, QuatationModel>();
quatationModelObj = AutoMapper.Mapper.Map(quatationObj, quatationModelObj);
return quatationModelObj;

public partial class Quatation
{
    public int QuatationId { get; set; } 
    public int FirmId { get; set; } 
    public int ItemId { get; set; } 
    public double Quantity { get; set; } 
    public decimal Price { get; set; } 
    public Nullable Dated { get; set; } 
    public Nullable IsDeleted { get; set; } 
    public Nullable CreatedDate { get; set; } 
    public Nullable CreatedBy { get; set; } 
    public Nullable ModifyDate { get; set; } 
    public Nullable ModifyBy { get; set; }

    public virtual Firm Firm { get; set; }
    public virtual Item Item { get; set; }
}

public class QuatationModel
{
    public int QuatationId { get; set; } 
    public int? FirmId { get; set; } 
    public int ItemId { get; set; } 
    public double Quantity { get; set; } 
    public decimal Price { get; set; } 
    public DateTime? Dated { get; set; } 
    public int IsDeleted { get; set; } 
    public DateTime? CreatedDate { get; set; } 
    public int? CreatedBy { get; set; } 
    public DateTime? ModifyDate { get; set; } 
    public int? ModifyBy { get; set; }

    //public string ItemName { get; set; }
    //public List<SelectListItem> LstFirm { get; set; }


    public virtual FirmModel Firm { get; set; }
    public virtual ItemModel Item { get; set; }
    //public IList<QuatationModel> LstQuatation { get; set; }
}

最佳答案

您必须确保具有相同名称的属性具有相同的类型。例如,一侧的 int 和另一侧的 Nullable 将不起作用 (IsDeleted)。

关于c# - “AutoMapper.AutoMapperMappingException”发生在 AutoMapper.dll 中,但未在用户代码中处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21798506/

相关文章:

c# - 如何将服务注入(inject)AutoMapper?

c# - 控制台应用程序错误 "Index (zero based) must be greater than or equal to zero and less than the size of the argument list"

c# - 不使用数据网格的 Silverlight MVVM 示例?

c# - SEO : A whois server that work for . SE 域名?

c# - 在 ASP.Net MVC 的 View 模型中验证嵌套模型

c# - 将多个来源合并到一个目的地

c# - System.Diagnostics.Trace.WriteLine 使用哪个跟踪源?

c# - 异常 : Cannot bind to the target method because its signature or security transparency is not compatible with that of the delegate type

c# - AutoMapper 和 DateTime 到字符串的映射不起作用

c# - AutoMapper-从ViewModel映射回DTO时,subObject保持为空