Reputation: 5355
Hi I have class in Entity Framework Like this:-
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; }
}
When I try to add an entry of this type to DB, I get an error. Invalid column Name "BusinessLine_ListItemId", "Country_ListItemId", "Region_ListItemId". Obviously they are referring to parents properties. But I don't understand the issue. Can anyone point me in the right direction.
Upvotes: 0
Views: 376
Reputation: 5355
The answer lies in the Entity Map file. These are the changes I needed to make:
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 });
Upvotes: 1