Im using entity framework code first 4.3 in c#
I got the following classes:
Class A
{
public string Name { get; set; }
public List<B> Bs { get; set; }
}
Class B
{
public string Name { get; set; }
}
There is one to many realationship from A to B.
When i try to load B list from A. I only get the first element from the list.
When i execute the following code, i expect a2 to contain both b’s, but actually it contains only one. does anyone can help spot the problem?
B b = new B() {Name = "b"};
A a = new A() {Name = "a",
Bs = new List<B>() { new B() {Name = "b1"}, new B() {Name = "b2"} };
using (var context = new MyContext())
{
context.As.Add(a);
context.SaveChanges();
}
using (var context = new MyContext())
{
var a2 = (from a in context.As.Include(a => a.Bs)
where a.Name == "a"
select a).Single();
}
Thanks
Can you post your actual code – the code you posted doesn’t compile, but with some small changes to some of your brackets and variable naming it does – but I get a different result than you, a2 contains both B’s, as expected, so the problem may lie somewhere else. Here’s the entire console app: