sprocket12
sprocket12

Reputation: 5488

Cannot look up into entity framework using in memory list

I'm looking up in my entities database using an in memory List but I get this error :

Unable to create a constant value of type 'System.Collections.Generic.List`1'. Only primitive types ('such as Int32, String, and Guid') are supported in this context.

The code Im using is this :

dgv.DataSource = (from x in Helper.Ctx.Planner where myList.Contains(x.Customer) select x).Take(100);

I researched this issue and found that its suggested I retrieved all the contents using ToList() first but the database is very big, and retrieving the whole thing over the network would take minutes each time.

I am using EF4.1 and VS 2010.

Please any solution?!

Upvotes: 0

Views: 240

Answers (1)

Magnus
Magnus

Reputation: 46929

Compare the Pk key of Customer instead of the complete object.

myList.Select(x => x.Id).Contains(x.Customer.Id)

Upvotes: 2

Related Questions