Page 1 of 2

Entity Framework Core 1.0 throws System.NullReferenceException by SaveChanges

Posted: Thu 30 Jun 2016 07:33
by seb1487
Hi,
I wanted to test Devart dotConnect Professional with Entity Framework Core 1.
But SaveChanges() throws a System.NullReferenceException.

Full Exception:

Code: Select all

System.NullReferenceException: Object reference not set to an instance to an object.
   at Devart.Common.Entity.c.q()
   at Microsoft.EntityFrameworkCore.Storage.RelationalLoggerExtensions.<>c__DisplayClass0_0.<LogCommandExecuted>b__0()
   at Microsoft.EntityFrameworkCore.Storage.RelationalLoggerExtensions.LogInformation[TState](ILogger logger, RelationalLoggingEventId eventId, Func`1 state, Func`2 formatter)
   at Microsoft.EntityFrameworkCore.Storage.RelationalLoggerExtensions.LogCommandExecuted(ISensitiveDataLogger logger, DbCommand command, Int64 startTimestamp, Int64 currentTimestamp)
   at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection connection, String executeMethod, IReadOnlyDictionary`2 parameterValues, Boolean openConnection, Boolean closeConnection)
   at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteReader(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues, Boolean manageConnection)
   at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.Execute(IRelationalConnection connection)
   --- Ende der internen Ausnahmestapelüberwachung ---
   at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.Execute(IRelationalConnection connection)
   at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(IEnumerable`1 commandBatches, IRelationalConnection connection)
   at Microsoft.EntityFrameworkCore.Storage.RelationalDatabase.SaveChanges(IReadOnlyList`1 entries)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(IReadOnlyList`1 entriesToSave)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(Boolean acceptAllChangesOnSuccess)
   at Microsoft.EntityFrameworkCore.DbContext.SaveChanges(Boolean acceptAllChangesOnSuccess)
Source: "Devart.Data.Oracle.Entity.EFCore"

Connection string:

Code: Select all

"Direct=true; Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.1.1)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=MyService))); User Id=UserId; Password=Password;"
Could you tell me why the error happen and how to solve it?

Re: Entity Framework Core 1.0 throws System.NullReferenceException by SaveChanges

Posted: Fri 01 Jul 2016 16:38
by Shalex
The current (9.1.45) build of dotConnect for Oracle supports Entity Framework Core RC2. To use it, either add the Devart EF Core Model item (via the Add > New Item > Data menu of project in Solution Explorer) to make Entity Developer to add the Entity Framework Core RC2 packages in your project automatically, or install RC2 packages manually (Package source: https://www.nuget.org/api/v2/):
> Install-Package Microsoft.EntityFrameworkCore.Relational -PreRelease

The EF Core RTM support will be included in the next public build of dotConnect for Oracle. We will notify you when it is available for download.

Re: Entity Framework Core 1.0 throws System.NullReferenceException by SaveChanges

Posted: Thu 07 Jul 2016 17:33
by Shalex
Entity Framework Core 1.0 RTM is supported in the newest (9.1.55) build of dotConnect for Oracle: https://www.devart.com/dotconnect/oracl ... story.html.

Re: Entity Framework Core 1.0 throws System.NullReferenceException by SaveChanges

Posted: Fri 08 Jul 2016 11:34
by seb1487
Thanks Shalex,
with 9.1.55 it works on Entity Framework Core 1.0 RTM, but i have found new Bugs.

1) Triggers are created with a carriage return on end. Oracle 10 cannot compile this triggers. (without works)

2) If a query with Enums is created, it doesn’t work. e.g.:

Code: Select all

context.Products.Where(o => o.Type == MyEnum.Software).ToList();

Workaround:

Code: Select all

var enumValue = (int)MyEnum.Software;
context.Products.Where(o => (int)o.Type == enumValue).ToList();

3) If a query with objects is created, it doesn’t work (possibly the same)

Code: Select all

var productCategory = context.ProductCategories.FirstOrDefault();
var product = context.Products.Where(o => o.CategoryId == productCategory.Id).ToList(); <-- Error

Workaround:

Code: Select all

var productCategory = context.ProductCategories.FirstOrDefault();
var productCategoryId = productCategory.Id;
var product = context.Products.Where(o => o.CategoryId == productCategoryId).ToList(); <-- Works

Re: Entity Framework Core 1.0 throws System.NullReferenceException by SaveChanges

Posted: Wed 13 Jul 2016 16:45
by Shalex
Thank you for your report. We will notify you when the issues are fixed.

Re: Entity Framework Core 1.0 throws System.NullReferenceException by SaveChanges

Posted: Mon 18 Jul 2016 14:44
by Shalex
seb1487 wrote:2) If a query with Enums is created, it doesn’t work. e.g.:

Code: Select all

context.Products.Where(o => o.Type == MyEnum.Software).ToList();
Workaround:

Code: Select all

var enumValue = (int)MyEnum.Software;
context.Products.Where(o => (int)o.Type == enumValue).ToList();
2. Please specify:
a) the exact text of the error and its full stack trace
b) the SQL generated by the provider (check via dbMonitor)
seb1487 wrote:3) If a query with objects is created, it doesn’t work (possibly the same)

Code: Select all

var productCategory = context.ProductCategories.FirstOrDefault();
var product = context.Products.Where(o => o.CategoryId == productCategory.Id).ToList(); <-- Error
Workaround:

Code: Select all

var productCategory = context.ProductCategories.FirstOrDefault();
var productCategoryId = productCategory.Id;
var product = context.Products.Where(o => o.CategoryId == productCategoryId).ToList(); <-- Works
3. Please specify:
a) the exact text of the error and its full stack trace
b) the SQL generated by the provider (check via dbMonitor)

Re: Entity Framework Core 1.0 throws System.NullReferenceException by SaveChanges

Posted: Tue 19 Jul 2016 07:05
by seb1487
Hi Shalex,
here are the asked informations.
2)
New knowledge:
Exception throws only if the enum value is passed into the function.

Code: Select all

public IEnumerable<Products> Get(MyEnum type)
{
	return context.Products.Where(o => o.Type == type).ToList();
}
Throws:

Code: Select all

System.InvalidOperationException occurred
  HResult=-2146233079
  Message=Rewriting child expression from type 'xxx.MyEnum' to type 'System.Int32' is not allowed, because it would change the meaning of the operation. If this is intentional, override 'VisitUnary' and change it to allow this rewrite.
  Source=System.Core
  StackTrace:
       at System.Linq.Expressions.ExpressionVisitor.ValidateChildType(Type before, Type after, String methodName)
       at System.Linq.Expressions.ExpressionVisitor.ValidateUnary(UnaryExpression before, UnaryExpression after)
       at System.Linq.Expressions.ExpressionVisitor.VisitBinary(BinaryExpression node)
       at System.Data.Common.CommandTrees.a.VisitBinary(BinaryExpression expression)
       at System.Data.Common.CommandTrees.a.b(SelectExpression A_0)
       at System.Data.Common.CommandTrees.b.b(SelectExpression A_0)
       at System.Data.Common.CommandTrees.a.c(SelectExpression A_0)
       at Microsoft.EntityFrameworkCore.Query.Expressions.SelectExpression.Accept(ExpressionVisitor visitor)
       at System.Linq.Expressions.ExpressionVisitor.VisitAndConvert[T](T node, String callerName)
       at Devart.Data.Oracle.Entity.z.a(SelectExpression A_0)
       at Microsoft.EntityFrameworkCore.Query.Expressions.SelectExpression.CreateDefaultQuerySqlGenerator()
       at Microsoft.EntityFrameworkCore.Query.Internal.ShaperCommandContext.GetRelationalCommand(IReadOnlyDictionary`2 parameters)
       at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable.Enumerator.MoveNext()
       at Microsoft.EntityFrameworkCore.Query.QueryMethodProvider.<_GroupJoin>d__26`4.MoveNext()
       at System.Linq.Enumerable.<SelectManyIterator>d__22`3.MoveNext()
       at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
       at System.Linq.Lookup`2.Create[TSource](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
       at System.Linq.GroupedEnumerable`3.GetEnumerator()
       at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
       at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()
       at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
       at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
       at xxx.<Get>d__5.MoveNext() in xxx.cs:line 60
  InnerException: 
SQL:

Code: Select all

No SQL generated.
3)

Code: Select all

var productCategory = context.ProductCategories.FirstOrDefault();
var product = context.Products.Where(o => o.CategoryId == productCategory.Id).ToList();
Throws:

Code: Select all

System.InvalidOperationException occurred
  HResult=-2146233079
  Message=Unexpected primitive type kind 'a'.
  Source=Devart.Data.Oracle.Entity.EFCore
  StackTrace:
       bei Devart.Common.Entity.cb.a(ck A_0)
       bei Devart.Common.Entity.b.f()
       bei System.Linq.Expressions.Expression.GetEqualityComparisonOperator(ExpressionType binaryType, String opName, Expression left, Expression right, Boolean liftToNull)
       bei System.Linq.Expressions.Expression.Equal(Expression left, Expression right, Boolean liftToNull, MethodInfo method)
       bei System.Linq.Expressions.BinaryExpression.Update(Expression left, LambdaExpression conversion, Expression right)
       bei System.Linq.Expressions.ExpressionVisitor.VisitBinary(BinaryExpression node)
       bei System.Data.Common.CommandTrees.a.VisitBinary(BinaryExpression expression)
       bei System.Linq.Expressions.ExpressionVisitor.VisitBinary(BinaryExpression node)
       bei System.Data.Common.CommandTrees.a.VisitBinary(BinaryExpression expression)
       bei System.Linq.Expressions.ExpressionVisitor.VisitBinary(BinaryExpression node)
       bei System.Data.Common.CommandTrees.a.VisitBinary(BinaryExpression expression)
       bei System.Data.Common.CommandTrees.a.b(SelectExpression A_0)
       bei System.Data.Common.CommandTrees.b.b(SelectExpression A_0)
       bei System.Data.Common.CommandTrees.a.c(SelectExpression A_0)
       bei Microsoft.EntityFrameworkCore.Query.Expressions.SelectExpression.Accept(ExpressionVisitor visitor)
       bei System.Linq.Expressions.ExpressionVisitor.VisitAndConvert[T](T node, String callerName)
       bei Devart.Data.Oracle.Entity.z.a(SelectExpression A_0)
       bei Microsoft.EntityFrameworkCore.Query.Expressions.SelectExpression.CreateDefaultQuerySqlGenerator()
       bei Microsoft.EntityFrameworkCore.Query.Internal.ShaperCommandContext.GetRelationalCommand(IReadOnlyDictionary`2 parameters)
       bei Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable.AsyncEnumerator.<MoveNext>d__8.MoveNext()
    --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
       bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       bei System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       bei Microsoft.EntityFrameworkCore.Query.Internal.AsyncLinqOperatorProvider.<_FirstOrDefault>d__82`1.MoveNext()
    --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
       bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       bei System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       bei Microsoft.EntityFrameworkCore.Query.Internal.TaskResultAsyncEnumerable`1.Enumerator.<MoveNext>d__3.MoveNext()
    --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
       bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       bei System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       bei Microsoft.EntityFrameworkCore.Query.Internal.AsyncLinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.<MoveNext>d__5.MoveNext()
    --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
       bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       bei System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       bei xxx.<Get>d__3.MoveNext() in xxx.cs:Zeile 49.
  InnerException: 
SQL:

Code: Select all

No SQL generated.

Re: Entity Framework Core 1.0 throws System.NullReferenceException by SaveChanges

Posted: Tue 19 Jul 2016 10:35
by Shalex
Thank you for the additional information. We are investigating the issue.

Re: Entity Framework Core 1.0 throws System.NullReferenceException by SaveChanges

Posted: Fri 22 Jul 2016 07:54
by Shalex
The new build of dotConnect for Oracle 9.1.67 is available for download now. It includes the following fixes:
  • The bug with generating triggers for Oracle 9/10/11 by EF Core Code-First migrations is fixed
  • The bug with convertation of enum values in parameters when using EF Core is fixed
Please try v9.1.67 and notify us about the result.

Re: Entity Framework Core 1.0 throws System.NullReferenceException by SaveChanges

Posted: Fri 22 Jul 2016 13:21
by seb1487
Hi Shalex,
1 and 2 are fixed and working.
3 is still open.

Re: Entity Framework Core 1.0 throws System.NullReferenceException by SaveChanges

Posted: Fri 22 Jul 2016 13:35
by Shalex
seb1487 wrote:3 is still open.
The investigation is in progress. We will notify you about the result.

Re: Entity Framework Core 1.0 throws System.NullReferenceException by SaveChanges

Posted: Thu 11 Aug 2016 15:28
by Shalex
seb1487 wrote:3 is still open.
The bug with long parameter names in EF Core is fixed in the newest (9.1.82) build of dotConnect for Oracle. Please try it and notify us about the result.

Re: Entity Framework Core 1.0 throws System.NullReferenceException by SaveChanges

Posted: Thu 18 Aug 2016 07:10
by seb1487
Hi Shalex,
the BugFix did not work. But the problem exists now only if the FK is nullable.

Democode can be downloaded here.

Re: Entity Framework Core 1.0 throws System.NullReferenceException by SaveChanges

Posted: Tue 23 Aug 2016 11:35
by Shalex
Thank you for your report. We have reproduced the "Unexpected primitive type kind 'a'." issue and are investigating it. We will notify you about the result.

Re: Entity Framework Core 1.0 throws System.NullReferenceException by SaveChanges

Posted: Fri 02 Sep 2016 14:34
by Shalex
The bug with nullable parameters in EF Core is fixed in the newest (9.1.97) build of dotConnect for Oracle: viewtopic.php?f=1&t=34216.