客户端评估

时间:2019-06-12 12:59:54

标签: c# asp.net-core entity-framework-core

我想在这里问什么可能导致客户端评估

以前Image是从数据库加载的,但是我将其更改为从File获得Documents,然后从数据库和上下文配置中的关系中删除了列,但是由于某些原因现在它在客户端评估

public class DocumentEntry
{
    public Guid Id { get; set; } = Guid.NewGuid();

    public List<File> Documents { get; set; } = new List<File>();

    public File Image => Documents.FirstOrDefault(x => x.Name.EndsWith("jpg"));

    public Author Author { get; set; }
}

public class File
{
    public Guid Id { get; set; } = Guid.NewGuid();

    public Document Document { get; set; }

    public Guid? DocumentId { get; set; }

    public string Name { get; set; }
}

public class Author
{
    public Guid Id { get; set; } = Guid.NewGuid();

    public string FirstName { get; set; }

    public string SecondName { get; set; }
}

var doc = _context
          .DocumentEntry
          .Include(x => x.Documents)
          .Include(x => x.Author)
          .FirstOrDefault(x => x.Documents.Any(c => c.Id == new Guid(id)));

warn: Microsoft.EntityFrameworkCore.Query[20500]
      The LINQ expression 'where ([c].Id == new Guid(__id_0))' could not be translated and will be evaluated locally.
warn: Microsoft.EntityFrameworkCore.Query[20500]
      The LINQ expression 'where  ?= (Convert(Property([x], "Id"), Nullable`1) == Property([c], "DocumentId")) =?' could not be translated and will be evaluated locally.
warn: Microsoft.EntityFrameworkCore.Query[20500]
      The LINQ expression 'Any()' could not be translated and will be evaluated locally.
warn: Microsoft.EntityFrameworkCore.Query[20500]
      The LINQ expression 'where {from File c in value(Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1[Common.Files.File]) where ([c].Id == new Guid(__id_0)) where  ?= (Convert(Property([x], "Id"), Nullable`1) == Property([c], "DocumentId")) =? select [c] => Any()}' could not be translated and will be evaluated locally.
warn: Microsoft.EntityFrameworkCore.Query[20500]
      The LINQ expression 'where ([c].Id == new Guid(__id_0))' could not be translated and will be evaluated locally.
warn: Microsoft.EntityFrameworkCore.Query[20500]
      The LINQ expression 'where  ?= (Convert(Property([x], "Id"), Nullable`1) == Property([c], "DocumentId")) =?' could not be translated and will be evaluated locally.
warn: Microsoft.EntityFrameworkCore.Query[20500]
      The LINQ expression 'Any()' could not be translated and will be evaluated locally.
warn: Microsoft.EntityFrameworkCore.Query[20500]
      The LINQ expression 'where ([c].Id == new Guid(__id_0))' could not be translated and will be evaluated locally.
warn: Microsoft.EntityFrameworkCore.Query[20500]
      The LINQ expression 'where  ?= (Convert(Property([x], "Id"), Nullable`1) == Property([c], "DocumentId")) =?' could not be translated and will be evaluated locally.
warn: Microsoft.EntityFrameworkCore.Query[20500]
      The LINQ expression 'Any()' could not be translated and will be evaluated locally.
warn: Microsoft.EntityFrameworkCore.Query[20500]
      The LINQ expression 'where {from File c in value(Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1[Common.Files.File]) where ([c].Id == new Guid(__id_0)) where  ?= (Convert(Property([x], "Id"), Nullable`1) == Property([c], "DocumentId")) =? select [c] => Any()}' could not be translated and will be evaluated locally.
warn: Microsoft.EntityFrameworkCore.Query[20500]
      The LINQ expression 'where ([c].Id == new Guid(__id_0))' could not be translated and will be evaluated locally.
warn: Microsoft.EntityFrameworkCore.Query[20500]
      The LINQ expression 'where  ?= (Convert(Property([x], "Id"), Nullable`1) == Property([c], "DocumentId")) =?' could not be translated and will be evaluated locally.
warn: Microsoft.EntityFrameworkCore.Query[20500]
      The LINQ expression 'Any()' could not be translated and will be evaluated locally.
warn: Microsoft.EntityFrameworkCore.Query[20500]
      The LINQ expression 'Take(1)' could not be translated and will be evaluated locally.
warn: Microsoft.EntityFrameworkCore.Query[20500]
      The LINQ expression 'Distinct()' could not be translated and will be evaluated locally.
warn: Microsoft.EntityFrameworkCore.Query[20500]
      The LINQ expression 'where ([c].Id == new Guid(__id_0))' could not be translated and will be evaluated locally.
warn: Microsoft.EntityFrameworkCore.Query[20500]
      The LINQ expression 'where  ?= (Convert(Property([x], "Id"), Nullable`1) == Property([c], "DocumentId")) =?' could not be translated and will be evaluated locally.
warn: Microsoft.EntityFrameworkCore.Query[20500]
      The LINQ expression 'Any()' could not be translated and will be evaluated locally.
warn: Microsoft.EntityFrameworkCore.Query[20500]
      The LINQ expression 'where {from File c in value(Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1[Common.Files.File]) where ([c].Id == new Guid(__id_0)) where  ?= (Convert(Property([x], "Id"), Nullable`1) == Property([c], "DocumentId")) =? select [c] => Any()}' could not be translated and will be evaluated locally.
warn: Microsoft.EntityFrameworkCore.Query[20500]
      The LINQ expression 'where ([c].Id == new Guid(__id_0))' could not be translated and will be evaluated locally.
warn: Microsoft.EntityFrameworkCore.Query[20500]
      The LINQ expression 'where  ?= (Convert(Property([x], "Id"), Nullable`1) == Property([c], "DocumentId")) =?' could not be translated and will be evaluated locally.
warn: Microsoft.EntityFrameworkCore.Query[20500]
      The LINQ expression 'Any()' could not be translated and will be evaluated locally.
warn: Microsoft.EntityFrameworkCore.Query[20500]
      The LINQ expression 'Take(1)' could not be translated and will be evaluated locally.
warn: Microsoft.EntityFrameworkCore.Query[20500]
      The LINQ expression 'Distinct()' could not be translated and will be evaluated locally.
warn: Microsoft.EntityFrameworkCore.Query[20500]
      The LINQ expression 'join AnonymousObject _x in {from DocumentEntry x in value(Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1[Common.Publikacje.DocumentEntry]) join User x.Author in value(Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1[Common.Users.User]) on Property([x], "AuthorId") equals Property([x.Author], "Id") into IEnumerable`1 x.Author_group from User x.Author in {[x.Author_group] => DefaultIfEmpty()} where {from File c in value(Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1[Common.Files.File]) where ([c].Id == new Guid(__id_0)) where  ?= (Convert(Property([x], "Id"), Nullable`1) == Property([c], "DocumentId")) =? select [c] => Any()} orderby EF.Property(?[x]?, "Id") asc select new AnonymousObject(new [] {Convert(EF.Property(?[x]?, "Id"), Object)}) => Take(1) => Distinct()} on Property([x.Documents], "DocumentId") equals Convert([_x].GetValue(0), Nullable`1)' could not be translated and will be evaluated locally.
warn: Microsoft.EntityFrameworkCore.Query[20500]
      The LINQ expression 'orderby [_x].GetValue(0) asc' could not be translated and will be evaluated locally.
warn: Microsoft.EntityFrameworkCore.Query[20500]
      The LINQ expression 'FirstOrDefault()' could not be translated and will be evaluated locally.

1 个答案:

答案 0 :(得分:2)

看看您是否可以稍微更改LINQ查询。

var guid = new Guid(id);
var doc = _context
          .DocumentEntry
          .Include(x => x.Documents)
          .Include(x => x.Author)
          .FirstOrDefault(x => x.Documents.Any(c => c.Id == guid));