Unable to create a constant value of type (type) Only primitive types ('such as Int32, String, and Guid') are supported in this context

前端 未结 4 615
离开以前
离开以前 2020-12-11 02:29

I\'ve read ALL of:

  • Unable to create a constant value of type 'System.Object' in Entity Framework

  • Entity Framework - "Unable to

4条回答
  •  囚心锁ツ
    2020-12-11 03:23

    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;
    }
    

提交回复
热议问题