Entity framework - exclude list of values

Posted by DutrowLLC on Stack Overflow See other posts from Stack Overflow or by DutrowLLC
Published on 2009-11-16T09:15:44Z Indexed on 2010/04/07 0:43 UTC
Read the original article Hit count: 348

Filed under:
|

Is there a way to exclude a list of values for an object attribute when querying the database through entity framework?

I tried to be slick and pull this number:

        List<String> StringList = new List<String>();
        StringList.Add("ya_mama");
        StringList.Add("has");
        StringList.Add("fleas");

        servicesEntities context = new servicesEntities();
        var NoFleasQuery = (from x in context.person
                            where !StringList.Any(y => y.CompareTo(x.the_string_I_dont_want_it_to_be) == 0)  // <--- the part where I thought I was slick
                            select x);

...it compiled, but after I ran it, it gave me this error: Unable to create a constant value of type 'Closure type'. Only primitive types ('such as Int32, String, and Guid') are supported in this context.

'Closure type'???? How about MY closure!!! Entity framework... you broke my heart.

© Stack Overflow or respective owner

Related posts about entity-framework

Related posts about c#