2017-06-05 69 views
0

您好我有類實體框架中像這樣: -實體框架無效列名稱錯誤

public partial class JLLContact : DomainEntity, IUniqueId 
{ 
    // Simple Props 
    public int? Record1ObjectTypeCode { get; set; } 
    public int? Record2ObjectTypeCode { get; set; } 
    public DateTime? CreatedOn { get; set; } 
    public string Email { get; set; } 
    public string Description { get; set; } 
    public bool IsActive { get; set; } 
    public int JLLContactId { get; set; } 
    public DateTime? ModifiedOn { get; set; } 
    public string Name { get; set; } 
    public string Title { get; set; } 
    public int? RoleLid { get; set; } 
    public int? BusinessLineLId { get; set; } 
    public int? RegionLId { get; set; } 
    public int? RelationScoreLId { get; set; } 
    public int? RelationStrengthLId { get; set; } 
    public int? Record1LId { get; set; } 
    public int? Record2LId { get; set; } 
    public bool? IsPrimary { get; set; } 
    public int? CountryLid { get; set; } 

    // UniqueId 
    public string __Id 
    { 
     get { return JLLContactId.ToString(); } 
    } 


    // Parents 
    public virtual ListItem Role { get; set; } 
    public virtual ListItem Region { get; set; } 
    public virtual ListItem Country { get; set; } 
    public virtual ListItem BusinessLine { get; set; } 

} 

當我嘗試添加此類型數據庫的條目,我得到一個錯誤。無效的列名稱爲「BusinessLine_ListItemId」,「Country_ListItemId」,「Region_ListItemId」。 顯然他們指的是父母的財產。但我不明白這個問題。任何人都可以指向正確的方向。

+1

這是Code First模型嗎?我們能否看到ListItem實體和配置(如果有的話)? –

+1

@IvanStoev - 你是對的。答案在於映射文件。我在下面進行了更改並進行了更改。 – SaiBand

回答

1

答案在於實體映射文件。這些是我需要做的改變:

this.HasOptional(t => t.Role).WithMany(t => t.Role_JLLContacts).HasForeignKey(d => new { d.RoleLid }); 
this.HasOptional(t => t.BusinessLine).WithMany(t => t.BusinessLine_JLLContacts).HasForeignKey(d => new { d.BusinessLineLId }); 
this.HasOptional(t => t.Region).WithMany(t => t.Region_JLLContacts).HasForeignKey(d => new { d.RegionLId });