hi have 2 table missions and missiondays with a relationship 1..n
I want select all missions that has all missiondays with an attribute called "visible" = true
I've tried with:
db.TDP_Missioni.Include("TDP_MissioniDestinazioni").where(p => p.TDP_MissioniDestinazioni.visible == true)
But there is an error. Indeed from p.TDP_MissioniDestinazioni i don't see the table's attributes. I think it's because the relationship is 1..n.
How can i do that?
thanks
Since the relationship is 1:N, the TDP_MissionDestinazioni should be a collection of missiondays. Try this: db.TDP_Missioni.Include("TDP_MissioniDestinazioni").where(p => p.TDP_MissioniDestinazioni.All(d => d.visible))
The above is using Lambda expressions not LINQ. Try:
var query = from m in db.TDP_Missioni
where m.TDP_MissioniDestinazioni.Any(md => md.Visible)
select m;
Or to fix your lambda query above all you need to do is use something like:
db.TDP_Missioni.Include("TDP_MissioniDestinazioni").
Where(p => p.TDP_MissioniDestinazioni.Any(d => d.Visible));
TDP_MissioniDestinazioni in relation to the TDP_Missioni table is a collection (based on the relationship) hence you need to iterate over each record in that able to get access to the visible
property of each MissionDay.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.