views:

22

answers:

2

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

A: 

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))

Stephen Cleary
A: 

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.

James