包括多个多对多集合导航属性

时间:2019-02-21 08:50:47

标签: c# entity-framework entity-framework-6 system.data.sqlite

说明

当尝试在已经嵌套的.Include()上急切地使用ICollection多对多ICollection属性时,我收到了EntityCommandCompilationExceptioninnerException:{ {1}}

  • 是否有任何(合适的)解决方法,或者EF6 / SQLite根本不支持此方法?如果不支持,将迁移到EntityFramework.Core吗?
  • 如果你们中的某些人可以确认这是一个限制,那么我将在SQLite问题跟踪器上创建一个问题

快速问题简介

System.NotSupportedException: APPLY joins are not supported.

这是失败的基本代码。有关完整的代码以及如何实现模型,请参见下文。

相反,仅包含两个// Bare minimum model definitions - see below for a full implementation public class Mode { [Key] public int Id { get; set; } } public class Type { [Key] public int Id { get; set; } } public class Preset { [Key] public string PresetId { get; set; } /* Note: Both Types and Modes are Many-To-Many Entity Relationship configured * using Join Table/Fluent API */ public ICollection<Type> Types { get; set; } = new List<Type>(); public ICollection<Mode> Modes { get; set; } = new List<Mode>(); } public class Plugin { [Key] public int Id { get; set; } public ICollection<Preset> Presets { get; set; } = new List<Preset>(); } public void test () { context.Plugins .Include("Presets.Modes") .Include("Presets.Types") .Load(); } // EntityCommandCompilationException An error occurred while preparing the command definition. See the inner exception for details. // innerException System.NotSupportedException: APPLY joins are not supported 导航属性中的一个可以正常工作:

ICollection

另外,在同一级别上包含多个context.Plugins .Include("Presets.Modes") .Load(); 可以正常工作:

ICollection

其他信息,环境

  • 该问题仅影响EntityFramework6System.Data.SQLite.EF6一起。据我所知EntityFramework.SqlServerCompact不受影响。
  • 我使用的是EF6 Code-First,我还没有尝试过EF6 Model-First或Database-First(并且切换到这两种方法都不适用)
  • 该问题仅在多对多集合导航属性中发生,并且仅当我尝试在同一级别上加载多个时出现
  • 我尝试了常见的替代方法,包括Select(),它会产生相同的异常
  • 我没有尝试构建手动联接或查询,因为这会导致我的项目中代码维护的损失极大
  • 在这一点上,我认为根本原因是SQLite EF6实现的局限性(似乎没有记录),而不是我可以使用代码轻松解决的问题
  • 我只发现了一个关于多个context.Presets .Include("Modes") .Include("Types") .Load(); 的类似StackOverflow question,并且(易于使用的)SQLite Bugtracker和邮件列表似乎都没有提到这个特定问题
  • 完整的源代码,包括带有测试数据的测试数据库,可以在我的GitHub EntityFrameworkResearch repository中找到。特别是Model definitionsDbContextrepro code

代码参考

.Include()

0 个答案:

没有答案
相关问题