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

Posted by Sheonarayan under Error and Solution on 5/9/2015 | Points: 10 | Views : 5050 | Status : [Administrator] | Replies : 0

The Problem


I was getting following error when I was trying to run a linq quiery

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

var subCats = db.HowToCategoriesSubs.Where(s => s.CategoryId.Equals(howtoDemo.CategoryId)).ToList();


The Solution


The solution to this problem is very simple, just change the ".equals" to "==".

var subCats = db.HowToCategoriesSubs.Where(s => s.CategoryId == howtoDemo.CategoryId).ToList();


It works great now !

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



Responses

(No response found.)

Login to post response