开发者

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

开发者 https://www.devze.com 2023-03-19 09:10 出处:网络
I have many to many entities relation ships Trace - Car I want to select select all Traces where Car.TypeId = 1

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

精彩评论

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