A constant variable of type 'System.Object' could not be created. In this environment, only primitive types ('such as Int32, String, and Guid') are supported.

entity-framework linq-to-entities

Question

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 there is a known issue on referencing non-scalar variables, but I'm not sure how to implement a workaround:

http://msdn.microsoft.com/en-us/library/bb896317.aspx#Y1442

private MovieLibraryDBEntities movieLibraryDBEntitiesContext;

public int getNumberOfEntriesReserved()
{
    return (from m in movieLibraryDBEntitiesContext.Movies
            where m.CheckedOut.Equals(1)
            select m).Count();

    //return movieLibraryDBEntitiesContext.Movies
    //  .Where(e => e.CheckedOut.Equals(1))
    //  .Select (e => e.Title).Count();
}
1
8
5/7/2011 7:46:05 PM

Popular Answer

You cannot use m.CheckedOut.Equals(1) in linq-to-entities query. Use m.CheckedOut == 1 but CheckedOut must be integer.

14
5/7/2011 7:44:58 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow