I\'ve read ALL of:
Unable to create a constant value of type 'System.Object' in Entity Framework
Entity Framework - "Unable to
I think that EF is trying to convert where a.Photos.Contains(p)
into SQL like WHERE p IN (a.Photos)
, but it doesn't know how to express a.Photos
in SQL. The SQL you want probably looks like WHERE p.Id IN (1, 2, 3)
, so you could try doing that in C#:
static IQueryable VisiblePhotos(this Album a)
{
var photoIds = a.Photos.Select(p => p.Id).ToArray();
return from p in VisibleObjects.OfType() where photoIds.Contains(p.Id) select p;
}