EF Core Include function broken in new release

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
oerha
Posts: 3
Joined: Sun 05 Nov 2017 11:39

EF Core Include function broken in new release

Post by oerha » Sun 05 Nov 2017 11:48

I recently updated to the last Devart release with netstandard 2.0 support, now all my linq expression with Include function are broken.

Code: Select all

this.Entities.Include(x => x.Posts).ThenInclude(x => x.Notes).Include(x => x.BlogUsers).Where(x => x.Id == 1).ToList();
Model:

Code: Select all

    public class Blog {
        public int Id { get; set; }
        public string Name { get; set; }
        public List<Post> Posts { get; set; }
        public List<BlogUser> BlogUsers { get; set; }
    }

    public class Post {
        public int Id { get; set; }
        public string Name { get; set; }
        public int BlogId { get; set; }
        public Blog Blog { get; set; }
        public List<Note> Notes { get; set; }
    }

    public class Note {
        public int Id { get; set; }
        public int PostId { get; set; }
        public Post Post { get; set; }
    }

    public class BlogUser {
        public int Id { get; set; }
        public int BlogId { get; set; }
        public Blog Blog { get; set; }
    }
Mapping:

Code: Select all

 modelBuilder.Entity<BlogUser>(s => {
                s.HasKey(e => e.Id);
                s.HasOne(e => e.Blog).WithMany(h => h.BlogUsers).HasForeignKey(h => h.BlogId);
                s.ToTable("BLOGUSER");
            });

            modelBuilder.Entity<Note>(s => {
                s.HasKey(e => e.Id);
                s.ToTable("NOTE");
                s.HasOne(e => e.Post).WithMany(h => h.Notes).HasForeignKey(h => h.PostId);
            });

            modelBuilder.Entity<Post>(s => {
                s.HasKey(e => e.Id);
                s.Property(e => e.Name).HasMaxLength(250);
                s.ToTable("POST");
                s.HasOne(e => e.Blog).WithMany(h => h.Posts).HasForeignKey(h => h.BlogId);
            });

            modelBuilder.Entity<Blog>(s => {
                s.HasKey(e => e.Id);
                s.ToTable("BLOG");
                s.Property(e => e.Name).HasMaxLength(250);
            });
Error:
at Devart.Data.Oracle.ay.b()
at Devart.Data.Oracle.am.f()
at Devart.Data.Oracle.am.e()
at Devart.Data.Oracle.c5.a(am A_0, Int32 A_1)
at Devart.Data.Oracle.c5.a(Int32 A_0, bg A_1)
at Devart.Data.Oracle.OracleCommand.InternalExecute(CommandBehavior behavior, IDisposable disposable, Int32 startRecord, Int32 maxRecords, Boolean nonQuery)
at Devart.Common.DbCommandBase.ExecuteDbDataReader(CommandBehavior behavior, Boolean nonQuery)
at Devart.Data.Oracle.Entity.ai.a(CommandBehavior A_0)
at Devart.Common.Entity.cj.d(CommandBehavior A_0)
at Devart.Data.Oracle.Entity.ai.b(CommandBehavior A_0)
at System.Data.Common.DbCommand.ExecuteReader()
at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary`2 parameterValues)
at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteReader(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.BufferlessMoveNext(Boolean buffer)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.MoveNext()
at Microsoft.EntityFrameworkCore.Query.Internal.QueryBuffer.IncludeCollection(Int32 includeId, INavigation navigation, INavigation inverseNavigation, IEntityType targetEntityType, IClrCollectionAccessor clrCollectionAccessor, IClrPropertySetter inverseClrPropertySetter, Boolean tracking, Object entity, Func`1 relatedEntitiesFactory)
at lambda_method(Closure , QueryContext , Blog , Object[] )
at Microsoft.EntityFrameworkCore.Query.Internal.IncludeCompiler._Include[TEntity](QueryContext queryContext, TEntity entity, Object[] included, Action`3 fixup)
at lambda_method(Closure , Blog )
at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()
at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.<_TrackEntities>d__17`2.MoveNext()
at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()
at System.Collections.Generic.List`1.AddEnumerable(IEnumerable`1 enumerable)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
To recreate, the table needs to have data in it

Shalex
Site Admin
Posts: 8245
Joined: Thu 14 Aug 2008 12:44

Re: EF Core Include function broken in new release

Post by Shalex » Tue 07 Nov 2017 14:54

We cannot reproduce the issue with the following code in .NET Core 2.0 project with both Oracle 12 and Oracle 11.2, Devart.Data.Oracle.EFCore -version 9.5.381, the database schema is created by runtime (then 1 record is manually added to each table):

Code: Select all

using Devart.Data.Oracle;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;

namespace ConsoleApp98
{
    class Program
    {
        static void Main(string[] args)
        {
            var monitor = new OracleMonitor() { IsActive = true };

            var context = new MyDbContext();

            context.Database.EnsureCreated();

            var result = context.Blogs.Include(x => x.Posts).ThenInclude(x => x.Notes).Include(x => x.BlogUsers).Where(x => x.Id == 1).ToList();
        }
    }

    public class MyDbContext : DbContext
    {
        public MyDbContext() : base()
        {
        }
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.Options.Extensions.OfType<RelationalOptionsExtension>().Any(ext => !string.IsNullOrEmpty(ext.ConnectionString) || ext.Connection != null))
                optionsBuilder.UseOracle(@"User Id=...;Password=...;Server=dboracle;Direct=True;Sid=orcl12c;Persist Security Info=True;License Key=...");
            base.OnConfiguring(optionsBuilder);
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<BlogUser>(s => {
                s.HasKey(e => e.Id);
                s.HasOne(e => e.Blog).WithMany(h => h.BlogUsers).HasForeignKey(h => h.BlogId);
                s.ToTable("BLOGUSER");
            });

            modelBuilder.Entity<Note>(s => {
                s.HasKey(e => e.Id);
                s.ToTable("NOTE");
                s.HasOne(e => e.Post).WithMany(h => h.Notes).HasForeignKey(h => h.PostId);
            });

            modelBuilder.Entity<Post>(s => {
                s.HasKey(e => e.Id);
                s.Property(e => e.Name).HasMaxLength(250);
                s.ToTable("POST");
                s.HasOne(e => e.Blog).WithMany(h => h.Posts).HasForeignKey(h => h.BlogId);
            });

            modelBuilder.Entity<Blog>(s => {
                s.HasKey(e => e.Id);
                s.ToTable("BLOG");
                s.Property(e => e.Name).HasMaxLength(250);
            });
        }

        public DbSet<Blog> Blogs { get; set; }
        public DbSet<Post> Posts { get; set; }
        public DbSet<Note> Notes { get; set; }
        public DbSet<BlogUser> BlogUsers { get; set; }
    }

    public class Blog
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public List<Post> Posts { get; set; }
        public List<BlogUser> BlogUsers { get; set; }
    }

    public class Post
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public int BlogId { get; set; }
        public Blog Blog { get; set; }
        public List<Note> Notes { get; set; }
    }

    public class Note
    {
        public int Id { get; set; }
        public int PostId { get; set; }
        public Post Post { get; set; }
    }

    public class BlogUser
    {
        public int Id { get; set; }
        public int BlogId { get; set; }
        public Blog Blog { get; set; }
    }
}
Please upload a small complete test project with the corresponding DDL/DML script to ftp://ftp.devart.com (credentials: anonymous / yourEmail). Also specify the version of your Oracle Server.

oerha
Posts: 3
Joined: Sun 05 Nov 2017 11:39

Re: EF Core Include function broken in new release

Post by oerha » Tue 07 Nov 2017 16:15

I have uploaded a project to your FTP:

IncludeTest.zip

Oracle: 12.1.0.2.0

Thanks,
Owen

Shalex
Site Admin
Posts: 8245
Joined: Thu 14 Aug 2008 12:44

Re: EF Core Include function broken in new release

Post by Shalex » Thu 09 Nov 2017 19:23

Thank you for the test project. We have reproduced the issue and are investigating it. We will notify you about the result.

Shalex
Site Admin
Posts: 8245
Joined: Thu 14 Aug 2008 12:44

Re: EF Core Include function broken in new release

Post by Shalex » Fri 10 Nov 2017 16:13

The bug with using multiple .Include() in EF Core 2 is fixed. Look forward to the next public build of dotConnect for Oracle.

oerha
Posts: 3
Joined: Sun 05 Nov 2017 11:39

Re: EF Core Include function broken in new release

Post by oerha » Fri 10 Nov 2017 20:09

ok, thanks.

Shalex
Site Admin
Posts: 8245
Joined: Thu 14 Aug 2008 12:44

Re: EF Core Include function broken in new release

Post by Shalex » Fri 24 Nov 2017 09:33

The new build of dotConnect for Oracle 9.5.399 is available for download: viewtopic.php?f=1&t=36257.

Post Reply