Reputation: 111
I'm try to migrate a system to ADO.NET Entity I have 3 table
A => (Id, Name, ...)
B => (Id, Domain, ...)
c => (IdA, IdB)
VS.NET generate 2 entity A and B and both have reference to the other table but this reference is a collection. I need make a join between tables.
from a in A join b in B on a.? equal b.?
where condition
select new { Name = a.Name, Domain = b.Domain };
I cant do that follow the reference in entity bu when the problem grows can be a problem. Any Help?
Upvotes: 0
Views: 1101
Reputation: 73102
You have a many-to-many between A and B.
VS.NET generate 2 entity A and B and both have reference to the other table but this reference is a collection.
EF does not need to map the join table (C), because it only contains the foreign keys.
Use the navigational properties on the entites to retrieve the records - EF will do a silent join via the JOIN table behind the scenes.
Query to get related B's for A
var query = ctx.As.Include("Bs").Select(x => x.Bs).ToList(); // List<B>
Query to get related A's for B
var query = ctx.Bs.Include("As").Select(x => x.As).ToList(); // List<A>
That is referred to as eager loading.
The alternative is to use lazy loading, where the relationship is fetched when you request it later on (i don't recommend this approach).
You don't need to perform explicit joins between the tables - use the navigational properties.
I cant do that follow the reference in entity bu when the problem grows can be a problem. Any Help?
I don't understand that sentence - perhaps you can clarify?
Upvotes: 2