EF6 include / select多个实体级别抛出NotSupportedException

时间:2014-05-06 05:05:50

标签: mysql entity-framework

这似乎非常类似于:EF4.1 multiple nested entity Includes gets NotSupportedException? 但异常消息不同,我们正在使用更新的库。

尝试加载具有3个级别的实体图表:Accounting Record包含多个AccountingOperation,其中每个AccountingOperation包含多个AccountingOperationLine。如果我想在第3级加载3个nevigation属性(1个综合帐户和2个分析帐户),则会出现以下例外情况,如下所示。

代码:

var v = dbEntities.Set<AccountingRecord>()
    .Include(ar => ar.AccountingRecordOperations.Select(
        aro => aro.AccountingRecordOperationLines.Select(arol => arol.AccountingSynthetic)))
    .Include(ar => ar.AccountingRecordOperations.Select(
        aro => aro.AccountingRecordOperationLines.Select(arol => arol.AccountingAnalytical1)))
    .Include(ar => ar.AccountingRecordOperations.Select(
        aro => aro.AccountingRecordOperationLines.Select(arol => arol.AccountingAnalytical2)))
    .ToList();

异常

NotSupportedException: All objects in the EntitySet 'DbEntities.Entities' must have unique primary keys. 
However, an instance of type '...AccountingSynthetic' and an instance of type '...AccountingRecordOperation' both have the same primary key value, 'EntitySet=Entities;ID=1104'
由于AccountingSynthetic和AccountingRecordOperation没有共享id,因此有些东西显然会混淆EF。

配置:

  • 模型第一
  • TPT
  • MySQL 5.6
  • MySQl Connector 6.8.3
  • EF 6.0

注意:

  • 所有实体都继承实体。
  • 合成帐户和分析帐户都与AccountingOperationLines有一对多的关系(这会让EF混淆吗?)

即使使用这样简单的查询,错误仍然存​​在:

var v = dbEntities.Set<AccountingRecord>()
    .Include(ar => ar.AccountingRecordOperations.Select(aro => aro.AccountingRecordOperationLines.Select(arol => arol.AccountingSynthetic)));

0 个答案:

没有答案