0

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.

2
  • 1
    Is this Code First model? Can we see the ListItem entity and configuration (if any)? Commented Jun 5, 2017 at 19:54
  • 1
    @IvanStoev - you were right. The answer lies in the mapping file. I made the changes below and put in the changes. Commented Jun 8, 2017 at 15:51

1 Answer 1

1

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 });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.