Entity framework and many to many queries unusable?
2010-02-28 00:20 AnyKoro 阅读(427) 评论(0) 编辑 收藏 举报
2
![]() ![]() 3
|
I'm trying EF out and I do a lot of filtering based on many to many relationships. For instance I have persons, locations and a personlocation table to link the two. I also have a role and personrole table.
EF will give me persons, roles and location entities. EDIT: Since EF will NOT generate the personlocation and personrole entity types, they cannot be used in the query. How do I create a query to give me all the persons of a given location with a given role? In SQL the query would be
I've looked, but I can't seem to find a simple solution. |
|||
|
![]() ![]() |
In Lambda :
query result:
Using Contains():
query result:
using join():
Query Result:
You may want test wich one is faster with large data. Good luck. Giuliano Lemes |
|||
|
![]() ![]() |
Note: Since it's in EF v1, we will NOT have PersonLocation and PersonRole generated as entities like what LINQ2SQL does Solution 1:
This looks nice and straightforward, but this generates ugly SQL script and its performance is ok. Solution 2: Here are breakdowns.
Combine three steps above into one:
It's sort of verbose. But this generates clean SQL query and performs well. |