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