ASP.NET Boilerplate V7.x 不适用于 EF Core 6.x 的编译模型

问题描述 投票:0回答:2

EF Core 6 提供了一项名为“编译模型”的功能,以实现更好的查询性能(速度提高 10 倍),但 ABP V7.x 无法运行编译模型。它抛出以下异常:

实体“Edition”定义了全局查询过滤器,并且是与实体“EditionFeatureSetting”关系的必需结束。当所需实体被过滤掉时,这可能会导致意外结果。将导航配置为可选,或者为导航中的两个实体定义匹配的查询过滤器。请参阅 https://go.microsoft.com/fwlink/?linkid=2131316 了解更多信息。 System.InvalidOperationException:实体类型“Edition”配置了查询过滤器。无法生成编译模型,因为不支持查询过滤器。 在 Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGenerator.Create(IEntityType 实体类型,CSharpRuntimeAnnotationCodeGeneratorParameters 参数) 在Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGenerator.CreateEntityType(IEntityType实体类型,IndentedStringBuilder mainBuilder,IndentedStringBuilder methodBuilder,SortedSet`1命名空间,String className,布尔可为空) 在 Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGenerator.GenerateEntityType(IEntityType 实体类型,字符串命名空间,字符串类名,布尔可为空) 在 Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGenerator.GenerateModel(IModel 模型,CompiledModelCodeGenerationOptions 选项) 在 Microsoft.EntityFrameworkCore.Scaffolding.Internal.CompiledModelScaffolder.ScaffoldModel(IModel 模型,字符串 outputDir,CompiledModelCodeGenerationOptions 选项) 在Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.Optimize(字符串outputDir,字符串modelNamespace,字符串contextTypeName) 在Microsoft.EntityFrameworkCore.Design.OperationExecutor.OptimizeContextImpl(字符串outputDir,字符串modelNamespace,字符串contextType) 在 Microsoft.EntityFrameworkCore.Design.OperationExecutor.OptimizeContext.<>c__DisplayClass0_0.<.ctor>b__0() 在 Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(操作操作) 实体类型“版本”配置了查询过滤器。无法生成编译模型,因为不支持查询过滤器。

请帮助和支持这个问题,因为编译的模型对于查询性能非常非常重要。

谢谢

c# aspnetboilerplate ef-core-6.0
2个回答
0
投票

该异常不是由ABP引起的。您的 EF 上下文至少配置了一个查询过滤器。已编译模型目前不支持任何查询过滤器,尽管它已在未来版本的待办事项中(请参阅此 GitHub 问题)。

目前唯一的选择是放弃查询过滤或放弃编译模型。


0
投票

我们正在添加全局过滤器。在文件 EntityType 的函数 CreateAnnotations 中

public static void CreateAnnotations(RuntimeEntityType runtimeEntityType)
{
    runtimeEntityType.AddAnnotation("Relational:FunctionName", null);
    runtimeEntityType.AddAnnotation("Relational:Schema", null);
    runtimeEntityType.AddAnnotation("Relational:SqlQuery", null);
    runtimeEntityType.AddAnnotation("Relational:TableName", "Application");
    runtimeEntityType.AddAnnotation("Relational:ViewName", null);
    runtimeEntityType.AddAnnotation("Relational:ViewSchema", null);
    Expression<Func<Application, bool>> expression = Application => !Application.IsDeleted;
    runtimeEntityType.AddAnnotation(CoreAnnotationNames.QueryFilter, expression);
    Customize(runtimeEntityType);
}
© www.soinside.com 2019 - 2024. All rights reserved.