I’m trying to populate class A (sorry for bad naming), with data from EF using Linq.
Got these classes:
public class A
{
public string SomeA { get; set; }
public B B { get; set; }
public List<C> C { get; set; }
}
public class B
{
public string SomeB { get; set; }
public string SomeB2 { get; set; }
}
public class C
{
public string SomeC { get; set; }
public string SomeC2 { get; set; }
}
My SQL query to get all info needed looks like:
SELECT * FROM A
JOIN B ON A.X = B.X
LEFT JOIN C ON C.X = B.X
How would the linq query look like to populate A?
List<A> things = ......
Thanks in advance
/Lasse
It’s easier than you might expect:
Note: for this to work, your EF model must understand there is a FK relationship between
BandC. When that’s the case (which will normally be when that FK is in the database and you generated your model directly from the database definition), EF will generate theCproperty onB(and vice versa).