开发者

Why can't I use more than levels in a select linq statement?

I have three tables in my database:

Why can't I use more than levels in a select linq statement?

What I want is to get items from the table wedstrijden like this:

int id = 3;
var wedstrijden = from w in db.wedstrijden 
                  where w.teams.teamleden.gebruikersid == id 
                  select w;

Unfortunately i get the following error:

Compiler Error Message: CS1593: Delegate 'System.Func' does not take 1 ar开发者_开发问答guments

Does anyone have a clue what's causing the error or where i can find the answer to my question?


The property wedstrijden.teams.teamleden is an enumerable so you have to check each item individually:

int id = 3;
var wedstrijden = from w in db.wedstrijden 
                  where w.teams.teamleden.Any(t => t.gebruikersid == id)
                  select w;


Your names are quite misleading because of plural/singular form misuse.

The problem isw.teams.teamleden.gebruikersid makes no sense with this diagram.

It looks like wedstrijden.teams means "teams" when in fact it is a single team.
Again, it looks like teams.teamleden is a single entity when in fact the relationship is one-to-many.

Because many teamleden entities match a single teams entity, you can't put a dot, it's just as meaningless as this:

from p in db.Products
where p.Owner.Orders.ID == id // what would you expect this to mean?
select p
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜