Entity Framework tries to translate context.Accounts.Contains (student) into an SQL statement (for example: "WHERE ... IN (...)"). He cannot translate it into an SQL statement, since he only knows how to handle primitive types (int, string ...), hence the exception.
You are probably trying to create an EF SQL statement, for example:
SELECT * FROM Accounts WHERE Id IN (1, 2, 3, 4, 5)
You can write a LINQ To Entities statement like this:
var studentIds = new int[] { 1, 2, 3, 4, 5 }; var matches = from account in context.Accounts where studentIds.Contains(account.Id) select account;
For more information, see the following blog post:
http://blogs.msdn.com/b/alexj/archive/2009/03/26/tip-8-writing-where-in-style-queries-using-linq-to-entities.aspx
The blog post I mentioned offers a job for the .NET 3.5 platform.
source share