开发者

Entity framework where conditoon on related entity with many-to-many relation

I have many to many entities relation ships

Trace - Car

I want to select select all Traces where Car.TypeId = 1

How may i do that?

var traces = (from s in repository.AsQueryable<Traces>(new List<string> { "Cars" })
                                 where s.Cars.TypeId== 1//how can I put this condition on collection?
                            开发者_开发问答     select s).FirstOrDefault();


Something like the following will do it

var traces = context.Traces.Where(t => t.Cars.Any(c => c.TypeId == 1));

This will give you a list of traces that contain a car with a TypeId of 1.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜