filter linq to sql with a entity framework where in

I am doing 2 linq queries one with entity framework and the other is linq to sql and they are not playing well together at all.

The first query grabs id's that are in one table via entity framework.

var pemdata = from pd in db.tblMap 
                          where pd.PID == pid
                          select new 
                          {
                              eid = pd.EID
                          };

And then I'm filtering the second query using a contains via linq to sql.

var data = from e in p.entities 
                       join et in p.entity_types on e.entity_type equals et.entity_types_id

                       where pemdata.Contains(e.entity_id) 

                       select new gEntities
                       {
                           entity_type = e.entity_type.ToString(),
                           Name = e.entity_name,
                           Type = et.entity_types_name,
                           Address = e.entity_address,
                           City = e.entity_city,
                           Zip = e.entity_zip.ToString()
                       };

The issue I'm seeing is an error.

Instance argument: cannot convert from 'System.Linq.IQueryable' to 'System.Linq.ParallelQuery'

'System.Linq.IQueryable' does not contain a definition for 'Contains' and the best extension method overload 'System.Linq.ParallelEnumerable.Contains(System.Linq.ParallelQuery, TSource)' has some invalid arguments

I usually don't have a problem doing a contains like this. but when I'm mixing linq to sql and entity framework I get this issue.

Any thoughts?

Answers


You'll need to materialize the first query before using the results. Easiest way is to just call .ToList() on it. Then you can use the results in the second query.

var pemdata = (from pd in db.tblMap 
                          where pd.PID == pid
                          select pd.EID).ToList();

Need Your Help

How is std::tuple implemented?

c++ c++11 tuples std

I'd like to know how are tuple implemented in standard library for C++0x. I tried to read description in libstdc++ manual and then read template listing, but it's really hard to understand how it w...

QLPreviewController's view

iphone ios qlpreviewcontroller

I just trying to get to QLPreviewController.view. Indeed, I want to catch a tap event on its view to show/hide toolbar etc. I am trying:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.