Click here to Skip to main content
15,881,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All

Suppose I have following structure.


C#
public class A
{
	public int ID{get;set;}
	public string Name{get;set;}
	public List< B> BList{get;set;}
}
public class B
{
	public int ID{get;set;}
	public int AID{get;set;}
	public string Name{get;set;}
	public A AObject{get;set;}
}
public class AMap:EntityTypeConfiguration<A>
{ 
   public AMap()
   {
	this.ToTable("ATable");

	this.HasKey(x => x.ID);
   }
}
public class BMap:EntityTypeConfiguration< B>
{
   public BMap()
   {
	this.ToTable("BTable");

	this.HasKey(x => x.ID);

	this.Property(x => x.AID).IsRequired();
	this.HasRequired(x => x.AObject).WithMany(x => x.BList).HasForeignKey(x => x.AID);
   }
}


When I get single record of ATable then it should bind list of BTable records in A object but I am getting BList null.

What am I missing here?
Posted
Updated 18-Feb-14 21:46pm
v2

1 solution

add a constructor for class A and initialize List BList

public A()
{
this.BList = new List < B > ();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900