LINQ to Entities only supports casting EDM primitive or enumeration types with IEntity interface

I was able to resolve this by adding the class generic type constraint to the extension method. I’m not sure why it works, though.

public static T GetById<T>(this IQueryable<T> collection, Guid id)
    where T : class, IEntity
{
    //...
}

Leave a Comment