EFCore 3.0.0 exception on saving

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Oracle
Post Reply
ggercman
Posts: 2
Joined: Tue 20 Aug 2019 12:40

EFCore 3.0.0 exception on saving

Post by ggercman » Mon 25 Nov 2019 08:57

Hi,
I'm getting System.NullReferenceException when trying to save changes, using .net core 3.0.0 console project, even with basic implementation.

Code: Select all

    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            string connectionString = @"User ID=****;Password=***;Host=****;Service Name=***;Port=1521;Direct=True;;License Key=***";

            ServiceCollection sc = new ServiceCollection();
            sc.AddDbContext<AppDbContext>(f => 
                f.EnableDetailedErrors()
                .UseOracle(connectionString)
                );

            
            using (var sp = sc.BuildServiceProvider())
            using (var scope = sp.CreateScope())
            using (var context = scope.ServiceProvider.GetRequiredService<AppDbContext>())
            {
                

                var b = new Language();
                b.Name = System.Guid.NewGuid().ToString();
                b.Code = System.Guid.NewGuid().ToString();

                context.Languages.Add(b);

                context.SaveChanges();
            }
        }
    }


    public class Language
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string Code { get; set; }
    }

    public class AppDbContext : DbContext
    {
        public DbSet<Language> Languages { get; set; }

        public AppDbContext(
            DbContextOptions<AppDbContext> options
            ) : base(options)
        {

        }
    }

Project

Code: Select all

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Devart.Data.Oracle.EFCore" Version="9.9.887" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.0.1" />
  </ItemGroup>

</Project>
Exception

Code: Select all

   at Microsoft.EntityFrameworkCore.Metadata.Internal.Property.OnAnnotationSet(String name, IConventionAnnotation annotation, IConventionAnnotation oldAnnotation)
   at Microsoft.EntityFrameworkCore.Metadata.Internal.ConventionAnnotatable.OnAnnotationSet(String name, Annotation annotation, Annotation oldAnnotation)
   at Microsoft.EntityFrameworkCore.Infrastructure.Annotatable.SetAnnotation(String name, Annotation annotation, Annotation oldAnnotation)
   at Microsoft.EntityFrameworkCore.Infrastructure.Annotatable.AddAnnotation(String name, Annotation annotation)
   at Microsoft.EntityFrameworkCore.Infrastructure.Annotatable.AddAnnotation(String name, Object value)
   at Devart.Data.Oracle.Entity.ai..ctor(IPropertyBase A_0)
   at Devart.Data.Oracle.Entity.ag.a(StringBuilder A_0, ModificationCommand A_1, String A_2, w A_3)
   at Devart.Data.Oracle.Entity.ag.AppendInsertOperation(StringBuilder commandText, ModificationCommand command, Int32 commandPosition)
   at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.UpdateCachedCommandText(Int32 commandPosition)
   at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.GetCommandText()
   at Devart.Common.Entity.cp.CreateStoreCommand()
   at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.Execute(IRelationalConnection connection)
   at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(DbContext _, ValueTuple`2 parameters)
   at Microsoft.EntityFrameworkCore.Storage.Internal.NoopExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
   at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(IEnumerable`1 commandBatches, IRelationalConnection connection)
   at Microsoft.EntityFrameworkCore.Storage.RelationalDatabase.SaveChanges(IList`1 entries)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(IList`1 entriesToSave)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(Boolean acceptAllChangesOnSuccess)
   at Microsoft.EntityFrameworkCore.DbContext.SaveChanges(Boolean acceptAllChangesOnSuccess)
   at Microsoft.EntityFrameworkCore.DbContext.SaveChanges()

AndreasReuss
Posts: 2
Joined: Thu 28 Nov 2019 08:10

Re: EFCore 3.0.0 exception on saving

Post by AndreasReuss » Thu 28 Nov 2019 08:17

I see exactly the same error in my code. (I upgraded my projects from EF core 2.2 to 3.0)

After that, I can't insert a record with devart dotconnect.

BUT if you set Id to a value different than 0 it works! (At least the record will be inserted in the DB, but the correct Id will not be set on the object you inserted either.)

Looking very much forward to hear Devart's answer on this one, since it is a really serious error.

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

Re: EFCore 3.0.0 exception on saving

Post by Shalex » Thu 28 Nov 2019 13:20

  • The bug with throwing System.NullReferenceException on SaveChanges() when inserting a new entity with value generated by the database in EF Core 3 is fixed
  • The bug with applying .ValueGeneratedOnAdd() to the string, guid, byte[] properties with .Key() and without .HasDefaultValueSql() in EF Core is fixed
The internal build with the fixes is available at https://download.devart.com/nuget_oracle_9_9_892.zip.

We will notify you when the new public build of dotConnect for Oracle is available for download.

AndreasReuss
Posts: 2
Joined: Thu 28 Nov 2019 08:10

Re: EFCore 3.0.0 exception on saving

Post by AndreasReuss » Thu 28 Nov 2019 14:14

I have tested, it seems to work nicely.

Thank you for swift reply and problem-solving.

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

Re: EFCore 3.0.0 exception on saving

Post by Shalex » Tue 24 Dec 2019 19:37

dotConnect for Oracle v9.10.909 is released: viewtopic.php?f=1&t=39716.

Post Reply