I am facing issue in foriegn key association for the below entites.
For example there are Three entities namely One, Two and Three. Two is depend on One, like that Three is depend on Two .
In Addition Two will many three's and One will have may two's(One to many)
Since Two and Three are depend on One and Two, I used Identifying relationship. But while foreign key mapping i am getting below exception ..
Two_Three_Source_Two_Three_Target: : The number of properties in the Dependent and Principal Roles in a relationship constraint must be identical
public class One
{
public long Id{get;set;}
public ICollection<Two> TwoList{get;set;}
}
public class Two
{
public long Id{get;set;}
public long OneId{ get; set; }
public ICollection<Three> ThreeList{get;set;}
}
public class Three
{
public long Id{get;set;}
public long TwoId{ get; set; }
}
public class OneMap: BaseEntityMap<One>
{
public OneMap()
{
this.HasKey(t => t.Id);
HasMany(t => t.Two).WithRequired().HasForeignKey(t => t.OneId);
ToTable("One");
}
}
public class TwoMap : BaseEntityMap<Two>
{
public TwoMap ()
{
this.HasKey(t => new { t.Id, t.OneId});
ToTable("Two");
HasMany(t => t.ThreeList).WithRequired().HasForeignKey(t => t.TwoId);
}
}
public class ThreeMap : BaseEntityMap<Three>
{
public ThreeMap ()
{
HasKey(t => new { t.Id, t.TwoId});
ToTable("Three");
}
}
I want help to fix this using Fluent Mapping
Edit
The reason i went for this apprach(Identifying Relationship) is to make below line work(To remove child records from db)
one.TwoList.Remove(item)