Hi.
I have public interface:
public interface IEntity
{
int ID { get; set; }
string Name { get; set; }
bool IsEnabled { get; set; }
}
which is implemented by some EF entities(throug partial class) and one extesion method:
public static IEnumerable<SelectListItem> ToSelectListItems<T>(this IQueryable<T> entities, int? selectedID = null) where T : IEntity
{
return entities.Select(c => new { c.Name, c.ID }).ToList().Select(c => new SelectListItem { Text = c.Name, Value = c.ID.ToString(), Selected = (c.ID == selectedID) });
}
Calling ToSelectListItems
return exception:
Unable to cast the type '<EF entity name>' to type 'IEntity'. LINQ to Entities only supports casting Entity Data Model primitive types.
Why, any ideas?
Thank you.