How do you specify a where clause on data returned from a .Include in an Entity Framework query?

Question!

Given the following database table hierarchy:

Region
------
RegionId
RegionName

Country
-------
CountryId
RegionId
CountryName

Destination
-----------
DestinationId
CountryId
DestinationName

Venue
-----
VenueId
DestinationId
VenueName

I have the following Entity Framework query:

var result = from region in context.Region.Include("Country.Destination.Venue") 
select region

which will return all rows from all tables (outer join)

Is it possible to introduce a where clause so that only rows where the venue is not null are included (or use an inner join) ?

Thanks



Answers

Try this. It should return the results you are looking for: only regions that have a corresponding venue.

    var result = from region in context.Region.Include(Country.Destination.Venue)
                 let v = (from ctry in region.Country
                         join dest in context.Destination
                         on ctry.CountryId
                         equals dest.CountryId
                         into destGroup
		                 from dests in destGroup
            		     join ven in context.Venue
            		     on dests.DestinationId
            		     equals ven.DestinationId
            		     into venGroup
                         select ctry).Any()
                 where v == true
                 select region;
By : YeahStu


Just a brainstormer here... On the laptop you can change the brightness using some key-kombinations on the keyboard. It should be possible to send those keyspresses If you just want to make it darker/lighter and not have to set it to a specific value.

By : Stefan


To add to DaEagles answer, the http://www.pinvoke.net/ site can be a life saver when working with win32-apis in .Net. If the information does not exist there, please add it when you have made a succesful interop for .Net.

By : Stefan


This video can help you solving your question :)
By: admin