Reputation: 1469
I have the code below:
public ActionResult OnDemand()
{
List<SiteMenu> all = new List<SiteMenu>();
using (MyDatabaseEntities dc = new MyDatabaseEntities())
{
all = dc.SiteMenus.Where(a => a.ParentMenuID.Equals(0)).ToList();
}
return View(all);
}
...but I get the error: Unable to create a constant value of type 'System.Object'. Only primitive types or enumeration types are supported in this context
...the error occurs on the following line:
all = dc.SiteMenus.Where(a => a.ParentMenuID.Equals(0)).ToList();
Could I get some help as to what I'm doing wrong? ...Thanks in Advance
Upvotes: 1
Views: 1676
Reputation: 3439
This should work fine:
all = dc.SiteMenus.Where(a => a.ParentMenuID == 0).ToList();
As the exception states: Only primitive types or enumeration types are supported in this context. Which means ParentMenuID
is an object type.
It should be either a primitive type or an enumeration type in order to use .Equals()
.
Upvotes: 2