Additional information: Unable to create a constant value of type 'System.Object'. Only primitive ty

Posted by Sheonarayan under ASP.NET on 6/13/2015 | Points: 10 | Views : 721 | Status : [Administrator] | Replies : 0
Problem


I was getting following error in the LINQ query with .Contains method.

list = db.HowtoDemoes.Where(d => d.CategoryId.Equals(cat) && (d.DemoName.Contains(q) || d.MetaKeyword.Contains(q))).ToList();


Additional information: Unable to create a constant value of type 'System.Object'. Only primitive types or enumeration types are supported in this context.

Solution


The problem was that first we need to convert the DbSet collection to List and then call LINQ methods. So change the code like this

list = db.HowtoDemoes.ToList() .Where(d => d.CategoryId.Equals(cat) && (d.DemoName.Contains(q) || d.MetaKeyword.Contains(q))).ToList();

It works nice now.

Regards,
Sheo Narayan
http://www.dotnetfunda.com



Responses

(No response found.)

Login to post response