Cannot compare elements exception in EF query

c#, entity-framework-4.1

Solution

The issue was because the myIds was null.

I needed to:

public ActionResult MyAction(List<int> myIds)
{
    if(myIds == null)
    {
        myIds = new List<int>();    
    }
    bool ignoreIds = !myIds.Any();

    var myList = from entry in db.Entries
                 where (ignoreIds || myIds.Contains(entry.Id))
                 select entry;
    return View(myList);
}

Problem

I have essentially: ``` public ActionResult MyAction(List<int> myIds) { var myList = from entry in db.Entries where (myIds == null || myIds.Contains(entry.Id)) select entry; return View(myList); } ``` The objective is to get only the items with the passed Ids or return all of them. (other criteria snipped for clarity) I am getting a exception when I return `myList`, I have done some debugging and it occurs when doing a `.ToList()` Cannot compare elements of type 'System.Collections.Generic.List`1'. Only primitive types (such as Int32, String, and Guid) and entity types are supported.

Original source

Related problems