微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

EF .NET Core 5 异常中的 LINQ 表达式 'OUTER APPLY Projection Mapping

如何解决EF .NET Core 5 异常中的 LINQ 表达式 'OUTER APPLY Projection Mapping

从 .NET Core 2.x 迁移到 .NET Core 5.0 后,我们面临这个问题。

错误添加代码以提高可读性)

 The LINQ expression 'OUTER APPLY Projection Mapping:
(
    SELECT e0.Id,e0.FirstName,e0.MiddleName,e0.LastName
    FROM Employees AS e0
    WHERE (((e0.Status != 4) && EXISTS (
        Projection Mapping:
        SELECT 1
        FROM FunctionRoles AS f0
        WHERE t.Id == f0.SchoolId)) && (e0.FunctionRoleId == (Projection Mapping:
            EmptyProjectionMember -> 0
        SELECT TOP(1) f1.Id
        FROM FunctionRoles AS f1
        WHERE (t.Id == f1.SchoolId) && (f1.Name == 'Manager')))) && (t.Id == e0.SchoolId)
) AS t0' Could not be translated. Either rewrite the query in a form that can be translated,or switch to client evaluation explicitly by inserting a call to 'AsEnumerable','AsAsyncEnumerable','ToList',or 'ToListAsync'. 
See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.

代码部分:

using (var dbContext = _contextProvider.CreateContext())
        {
            var school = dbContext.Set<Domain.Model.School>()
                .Where(s => s.Id == schoolId)
                .Select(s => new SchoolSummaryDto
                {
                    

                    //... Some other properties

                    DocumentTemplates = s.DocumentTemplates != null ? s.DocumentTemplates.Select(a => new DocumentTemplateDto
                    { Id = a.Id,Description = a.Description,SchoolId = a.SchoolId,FileName = a.FileName,DocumentTemplateTypeId = a.DocumentTemplateTypeId }).ToList() : new List<DocumentTemplateDto>(),// This below chunk is causing problem.
                    Signers = s.Employees != null ? s.Employees.AsEnumerable().Where(
                        e => e.Status != PersistentStatusEnum.Removed &&
                        e.FunctionRoleId == s.FunctionRoles.AsEnumerable().Single(
                        b => b.Name == FunctionRolesEnum.Manager.ToString()).Id).AsEnumerable().Select(
                        a => new NameValueType { Id = a.Id,Name = string.Format("{0} {1} {2}",a.FirstName,a.MiddleName,a.LastName) }).ToList() : new List<NameValueType>(),// .. Error chunk ends here

                    ContactPerson = s.ContactPerson,Email = s.Email,PhoneNumber = s.PhoneNumber,SchoolId = s.Id,SchoolName = s.Name,Website = s.Website,IsEnabled = s.IsEnabled,IsRegistered = s.IsRegistered
                }).FirstOrDefault();

        }

我的尝试: 根据这些 Microsoft 链接 Breaking ChangesQueryable projection not supported,我尝试并应用了相应的更改 AsEnumerable(),如上所示。

现在需要进行哪些更改?

图书馆和环境:

  1. 数据库 => MysqL
  2. 库 => Pomelo.EntityFrameworkCore.MysqL (5.0.0-alpha.2) Nuget Link

我感觉要么是这个 MysqL 库导致了问题,要么是 EF Core 5 的重大更改

编辑 1:

public class FunctionRole:AuditableEntity
{
    public string Name { get; set; }
    public string Description { get; set; }
    public Guid SchoolId { get; set; }
    public virtual School School { get; set; }
}

public class School:AuditableEntity
{
    public bool IsRegistered { get; set; }
    public bool IsEnabled { get; set; }
    public string Name { get; set; }
    public string Email { get; set; }
    public string Website { get; set; }
    public string PhoneNumber { get; set; }
    public string ContactPerson { get; set; }
    public string ActivationCode { get; set; }

    public virtual ICollection<FunctionRole> FunctionRoles { get; set; }

    public virtual ICollection<DocumentTemplate> DocumentTemplates { get; set; }
    

}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?