1

This seems very much similar to: EF4.1 multiple nested entity Includes gets NotSupportedException? But the exception message is different and we are using a newer libraries.

Trying to load an entity graph with 3 levels made of: Accounting Record which contains multiple AccountingOperation(s) which in turn each of them contain multiple AccountingOperationLine(s). The exception below occurs if I want to load the 3 nevigation properties on the 3rd level (1 synthetical and 2 analytical accounts) as shown below.

Code:

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();

Exception

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'

Something clearly confuses EF since AccountingSynthetic and AccountingRecordOperation don't share the id.

Configuration:

  • Model first
  • TPT
  • MySQL 5.6
  • MySQl Connector 6.8.3
  • EF 6.0

Notes:

  • All entities inherit of Entity.
  • The synthetic and analytical accounts all of them have a one to many relation to AccountingOperationLines (could this confuse EF?)

The error persist even with this simpler query like:

var v = dbEntities.Set<AccountingRecord>()
    .Include(ar => ar.AccountingRecordOperations.Select(aro => aro.AccountingRecordOperationLines.Select(arol => arol.AccountingSynthetic)));
Community
  • 1
  • 1
edif
  • 21
  • 3
  • Did you thoroughly check the types of your navigation properties? They are very similar, so with intellisense it is easy to make a mistake. – Dabblernl May 06 '14 at 05:18
  • Yes I checked before posting - no shared ids between the reported entity types. The navigation properties are correct, i will post later a diagram of the model which include only the the involved classes. – edif May 06 '14 at 06:28
  • well, apparently I need 10 reputation to add an image... – edif May 10 '14 at 11:20
  • I resolved the issue by upgrading to mysql connector 6.9.1 – edif Sep 19 '14 at 10:56

0 Answers0