Problem with .Contains

Posted by Rene on Stack Overflow See other posts from Stack Overflow or by Rene
Published on 2010-04-19T14:51:00Z Indexed on 2010/04/19 14:53 UTC
Read the original article Hit count: 395

Filed under:
|

Hello there,

I have a little problem which i can't solve. I want to use an SQL-In-Statement in Linq. I've read in this Forum and in other Forums that I have to use the .Contains (with reverse-thinking-notation :-)). As input i have a List of Guids. I first copied them into an array and then did something like that :

datatoget = (from p in objectContext.MyDataSet where ArrayToSearch.Contains(p.Subtable.Id.ToString()) select p).ToList();

datatoget is the result in which all records matching the Subtable.Id (which is a Guid) should be stored. Subtable is a Detail-Table from MyData, and the Id is a Guid-Type. I've tried several things (Convert Guid to String, and then using .Contains, etc), but I always get an Exception which says :

'Linq to Entities' doesn't recognize the Method 'Boolean Contains(System.Guid) and is not able to Translate this method into a memory expression. (Something like that, because I'm using the German Version of VS2008)

I am using L2E with .NET 3.5 and am programming in C# with VS 2008.

I've read several Examples, but it doesn't work. Is it perhaps because of using Guid's instead of strings ? I've also tried to write my own compare-function, but I don't know how to integrate it so that .NET calls my function for comparing.

© Stack Overflow or respective owner

Related posts about linq-to-entities

Related posts about .contains