Unable to create a constant value of type 'System.Object'. Only primitive types ('such as Int32, String, and Guid') are supported in this context

前端 未结 3 1622
时光说笑
时光说笑 2021-01-18 00:18

I\'m using MVC and Entity Framework. I\'ve created a class in my model folder with this code below. I keep getting the error message above with both queries below. I know

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-18 01:10

    This is an older question. I had the same problem when trying to filter a nullable column using the IQueryable interface. I solved the problem by first checking to see if the object had a value and then checking the value.

    widgets = widgets.Where(x => x.ID.HasValue.Equals(true) &&  x.ID.Value.Equals(widgetID));
    

提交回复
热议问题