After upgrating to Devart.Data,Oracle 9.11.980.0 and Entity Framework 6.4 is not possible to include 2 subcollections. If only one subcollection is included the query is generated.
Working
IQueryable<City> query = new Context().Set<City>().AsQueryable();
query = query.Include("Schools");
query = query.Include("Schools.Teachers");
Working
IQueryable<City> query = new Context().Set<City>().AsQueryable();
query = query.Include("Schools");
query = query.Include("Schools.Students");
Not Working
IQueryable<City> query = new Context().Set<City>().AsQueryable();
query = query.Include("Schools");
query = query.Include("Schools.Teachers");
query = query.Include("Schools.Students");
Following exception is thrown:
System.Data.Entity.Core.EntityCommandCompilationException : An error occurred while preparing the command definition. See the inner exception for details.
----> System.ArgumentException : An item with the same key has already been added.
at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition..ctor(DbProviderFactory storeProviderFactory, DbCommandTree commandTree, DbInterceptionContext interceptionContext, IDbDependencyResolver resolver, BridgeDataReaderFactory bridgeDataReaderFactory, ColumnMapFactory columnMapFactory)
at System.Data.Entity.Core.EntityClient.Internal.EntityProviderServices.CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree, DbInterceptionContext interceptionContext)
at System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlanFactory.CreateCommandDefinition(ObjectContext context, DbQueryCommandTree tree)
at System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlanFactory.Prepare(ObjectContext context, DbQueryCommandTree tree, Type elementType, MergeOption mergeOption, Boolean streaming, Span span, IEnumerable`1 compiledQueryParameters, AliasGenerator aliasGenerator)
at System.Data.Entity.Core.Objects.EntitySqlQueryState.GetExecutionPlan(Nullable`1 forMergeOption)
at System.Data.Entity.Core.Objects.ObjectQuery.ToTraceString()
at Temp.Tests.DevartTests.Test() in C:\dev\tfs\Dev_Gain5\Infra\Solution\Temp.Tests\DevartTests.cs:line 25
--ArgumentException
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at System.Data.Common.CommandTrees.b.b(f A_0)
at System.Data.Common.CommandTrees.d.a(DbApplyExpression A_0)
at System.Data.Common.CommandTrees.b.b(DbExpressionBinding A_0)
at System.Data.Common.CommandTrees.d.a(DbExpressionBinding A_0)
at System.Data.Common.CommandTrees.b.a(DbProjectExpression A_0)
at System.Data.Common.CommandTrees.b.b(DbExpressionBinding A_0)
at System.Data.Common.CommandTrees.d.a(DbExpressionBinding A_0)
at System.Data.Common.CommandTrees.b.a(DbSortExpression A_0)
at System.Data.Common.CommandTrees.b.b(DbExpressionBinding A_0)
at System.Data.Common.CommandTrees.d.a(DbExpressionBinding A_0)
at System.Data.Common.CommandTrees.b.a(DbProjectExpression A_0)
at System.Data.Common.CommandTrees.b.a(DbExpression A_0)
at System.Data.Common.CommandTrees.a.a(DbQueryCommandTree A_0, bt& A_1, b& A_2)
at System.Data.Common.CommandTrees.c.a(DbQueryCommandTree A_0)
at System.Data.Common.CommandTrees.a.a(DbCommandTree A_0)
at Devart.Data.Oracle.Entity.OracleEntityProviderServices.a(al A_0, DbCommandTree A_1)
at Devart.Data.Oracle.Entity.OracleEntityProviderServices.CreateDbCommandDefinition(DbProviderManifest baseProviderManifest, DbCommandTree commandTree)
at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition..ctor(DbProviderFactory storeProviderFactory, DbCommandTree commandTree, DbInterceptionContext interceptionContext, IDbDependencyResolver resolver, BridgeDataReaderFactory bridgeDataReaderFactory, ColumnMapFactory columnMapFactory)
Full sample test:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using Devart.Data.Oracle;
using NUnit.Framework;
namespace Temp.Tests
{
[TestFixture]
public class DevartTests
{
[Test]
public void Test()
{
IQueryable<City> query = new Context().Set<City>().AsQueryable();
query = query.Include(x=>x.Schools);
query = query.Include("Schools.Teachers");
query = query.Include("Schools.Students");
string sql = ((DbQuery<City>)query).Sql;
Assert.IsNotNull(sql);
}
}
[DbConfigurationType(typeof(Devart.Data.Oracle.Entity.OracleEntityProviderServicesConfiguration))]
public class Context : DbContext
{
public Context()
: base(new OracleConnection("[ORACLE Connection 12.2]"), false)
{
Database.SetInitializer<Context>(null);
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<City>();
modelBuilder.Entity<School>();
modelBuilder.Entity<Teacher>();
modelBuilder.Entity<Student>();
}
}
public class City
{
public City()
{
Schools = new List<School>();
}
[Key]
public int Id { get; set; }
public IList<School> Schools { get; set; }
}
public class School
{
public School()
{
Students = new List<Student>();
Teachers = new List<Teacher>();
}
[Key]
public int Id { get; set; }
public int CityId { get; set; }
public IList<Student> Students { get; set; }
public IList<Teacher> Teachers { get; set; }
}
public class Student
{
[Key]
public int Id { get; set; }
public int SchoolId { get; set; }
}
public class Teacher
{
[Key]
public int Id { get; set; }
public int SchoolId { get; set; }
}
}
Devart.Data.Oracle 9.11.980.0 An item with the same key has already been added.
Devart.Data.Oracle 9.11.980.0 An item with the same key has already been added.
Last edited by czlatea on Fri 12 Jun 2020 06:35, edited 1 time in total.
Re: Devart.Data,Oracle 9.11.980.0 An item with the same key has already been added.
We have reproduced the issue and are investigating it. We will notify you about the result.
Re: Devart.Data.Oracle 9.11.980.0 An item with the same key has already been added.
The bug with including several subcollections in LINQ query in EF 6.4 is fixed in v9.11.1034: viewtopic.php?f=1&t=41287.