Automapper映射不正确?

时间:2015-03-17 21:34:54

标签: automapper

我有两个对象,Project是一个数据库实体和IProject,我试图保存到数据库中:

public interface IProject
{
    int ProjectID { get; set; }
    string JobNumber { get; set; }
    string JobName { get; set; }
    string ProjectLocation { get; set; }
    int? FeeTypeID { get; set; }
    decimal? Fee { get; set; }
    decimal? ConstructionCost { get; set; }
    decimal? CostPerSquareFoot { get; set; }
    decimal? SquareFoot { get; set; }
    string Memo { get; set; }
    DateTime? DateCompleted { get; set; }
    int JobStatusID { get; set; }
    int ProjectTypeID { get; set; }
}

//The inheritance is actually in a partial class that doesn't get overridden

 public partial class Project : IProject
{
    public Project()
    {
        this.ProjectContacts = new HashSet<ProjectContact>();
        this.ProjectConsultants = new HashSet<ProjectConsultant>();
    }

    public int ProjectID { get; set; }
    public string JobNumber { get; set; }
    public string JobName { get; set; }
    public Nullable<int> FeeTypeID { get; set; }
    public Nullable<decimal> Fee { get; set; }
    public int JobStatusID { get; set; }
    public string Memo { get; set; }
    public Nullable<decimal> Acreage { get; set; }
    public Nullable<decimal> SquareFoot { get; set; }
    public Nullable<decimal> ConstructionCost { get; set; }
    public Nullable<decimal> BudgetPrice { get; set; }
    public Nullable<decimal> ActualPrice { get; set; }
    public Nullable<System.DateTime> DateCompleted { get; set; }
    public Nullable<decimal> CostPerSquareFoot { get; set; }
    public string ProjectLocation { get; set; }
    public int ProjectTypeID { get; set; }
    public Nullable<System.DateTime> StartDate { get; set; }
    public Nullable<int> PhaseID { get; set; }
    public string ProjectDescription { get; set; }
    public Nullable<int> ArchitectID { get; set; }
    public Nullable<int> ManagerID { get; set; }
    public Nullable<int> ArchiveLocationID { get; set; }

    public virtual ICollection<ProjectContact> ProjectContacts { get; set; }
    public virtual FeeType FeeType { get; set; }
    public virtual JobStatu JobStatu { get; set; }
    public virtual ICollection<ProjectConsultant> ProjectConsultants { get; set; }
    public virtual Person Person { get; set; }
    public virtual ArchiveLocation ArchiveLocation { get; set; }
    public virtual Person Person1 { get; set; }
    public virtual Phase Phase { get; set; }
    public virtual ProjectType ProjectType { get; set; }
}

我创建了地图:

Mapper.CreateMap<IProject, Data.Project>();

但是出于某种原因,每当我打电话给地图时:

//mappingService is a wrapper I have around Automapper so that I can inject it
var project = _mappingService.Map<IProject, Data.Project>(request);

我收到此错误:

Missing type map configuration or unsupported mapping.

Mapping types:
RuntimeType -> FeeType
System.RuntimeType -> Renaissance.Data.FeeType

Destination path:
Project.FeeType.FeeType

Source value:
System.Decimal

我在任何时候都没有尝试这样做。名称匹配,即使我明确告诉它映射:

.ForMember(dest => dest.Fee, opt => opt.MapFrom(src => src.Fee))

同样的消息仍然是错误的。

我错过了什么?

更新 这有效:

 .ForMember(dest => dest.FeeType, opt => opt.Ignore());

我认为我需要做到这一点。我不应该忽略目标中不存在/不与source属性中的某个名称相同的属性。

0 个答案:

没有答案
相关问题