views:

118

answers:

1

Hi experts, I am working on a website similar to nerddinner. Is it possible to perform similar join using Linq to entities what is done with linq to sql in nerddinner. I am posting the codes below.

public IQueryable<Dinner> FindByLocation(float latitude, float longitude) {
        var dinners = from dinner in FindUpcomingDinners()
                      join i in db.NearestDinners(latitude, longitude) 
                      on dinner.DinnerID equals i.DinnerID
                      select dinner;

        return dinners;
    }

I want to replace this codes with linq to entities implementation.

Regards

Parminder

A: 

Could you just look for where they intersect like:

FindUpcomingDinners().Intersect(db.NearestDinners(latitude, longitude)).ToList();

I am not sure what FindUpcomingDinners returns but the easiest would be to have two functions that return IEnumerables for FindUpcomingDinners and NearestDinners and then just get the intersect of the two lists.

Eg:

List<Dinner> upcomingDinners = FindUpcomingDinners();
List<Dinner> nearestDinners = NearestDinners(latitude, longitude);

List<Dinner> result = upcomingDinners.Intersect(nearestDinners).ToList();
Kelsey
thanks Kelseybut i get the folowing error"Unable to create a constant value of type 'System.Linq.EnumerableQuery`1'. Only primitive types ('such as Int32, String, and Guid') are supported in this context."Regards
Parminder
@Parminder were you able to figure this out? If this answer helped you don't forget to mark it as the accepted answer.
Kelsey
@Kelsey thanks, but its possible only in EF4.
Parminder