Home > OS >  Linq to Entity Framework : unable to create a constant value of type ''. Only primitive ty
Linq to Entity Framework : unable to create a constant value of type ''. Only primitive ty

Time:10-21

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();

CodePudding user response:

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)

  • Related