Search code examples
c#linqlinq-to-entities

Linq to Entity Framework : unable to create a constant value of type ''. Only primitive types or enumeration types are supported in this context


I am trying to select from a table where list contains a value using linq and entity framework. but its telling me it cannot create a constant and throwing an exception. If you comment out the && list parts, it works fine. What am I doing wrong?

var DbQry = (from data in Db.ACCESS
             where data.Active == true                                                                                                                             
                   && List.Select(s => s.Study).Contains(data.Study)
                   && List.Select(s => s.System).Contains(data.System)
             select data).ToList();

Solution

  • I assume, the properties Study and System are classes (and not a primitive type) and List is a user defined variable.

    If that's the case, can you try comparing with the identifiers like List.Select(s => s.Study.Id).Contains(data.Study.Id)