Bug #80707 | Problem with Microsoft EF 6 and MySql - null reference on SqlGenerator | ||
---|---|---|---|
Submitted: | 11 Mar 2016 16:16 | Modified: | 14 Mar 2016 6:46 |
Reporter: | George Domingos dos Ramos | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | Connector / NET | Severity: | S2 (Serious) |
Version: | .Net Connector 6.9.8 | OS: | Any |
Assigned to: | CPU Architecture: | Any | |
Tags: | .net Connector, EF, entityframework, SqlGenerator |
[11 Mar 2016 16:16]
George Domingos dos Ramos
[11 Mar 2016 17:03]
George Domingos dos Ramos
Sorry, i mean like this bug https://bugs.mysql.com/bug.php?id=77735
[14 Mar 2016 6:46]
Chiranjeevi Battula
Hello George Domingos dos Ramos, Thank you for the bug report. Verified this behavior on Visual Studio 2013 (C#.Net) with MySQL Connector/Net 6.9.8. Thanks, Chiranjeevi.
[14 Mar 2016 6:47]
Chiranjeevi Battula
Test Name: TestMethod1 Test FullName: _80707.UnitTest1.TestMethod1 Test Source: d:\Projects\80707\80707\UnitTest1.cs : line 19 Test Outcome: Failed Test Duration: 0:00:01.4640299 Result Message: Test method _80707.UnitTest1.TestMethod1 threw exception: System.NullReferenceException: Object reference not set to an instance of an object. Result StackTrace: at MySql.Data.Entity.CaseFragment.Accept(SqlFragmentVisitor visitor) at MySql.Data.Entity.BinaryFragment.Accept(SqlFragmentVisitor visitor) at MySql.Data.Entity.BinaryFragment.Accept(SqlFragmentVisitor visitor) at MySql.Data.Entity.BinaryFragment.Accept(SqlFragmentVisitor visitor) at MySql.Data.Entity.BinaryFragment.Accept(SqlFragmentVisitor visitor) at MySql.Data.Entity.SqlGenerator.FuseSelectWithInnerSelect(SelectStatement outer, SelectStatement inner) at MySql.Data.Entity.SqlGenerator.TryFusingSelect(InputFragment f) at MySql.Data.Entity.SqlGenerator.VisitInputExpression(DbExpression e, String name, TypeUsage type) at MySql.Data.Entity.SelectGenerator.VisitInputExpressionEnsureSelect(DbExpression e, String name, TypeUsage type) at MySql.Data.Entity.SelectGenerator.Visit(DbProjectExpression expression) at System.Data.Entity.Core.Common.CommandTrees.DbProjectExpression.Accept[TResultType](DbExpressionVisitor`1 visitor) at MySql.Data.Entity.SelectGenerator.GenerateSQL(DbCommandTree tree) at MySql.Data.MySqlClient.MySqlProviderServices.CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree) at System.Data.Entity.Core.Common.DbProviderServices.CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree, DbInterceptionContext interceptionContext) at System.Data.Entity.Core.Common.DbProviderServices.CreateCommandDefinition(DbCommandTree commandTree, DbInterceptionContext interceptionContext) 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.Common.DbProviderServices.CreateCommandDefinition(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.ELinq.ELinqQueryState.GetExecutionPlan(Nullable`1 forMergeOption) at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass7.<GetResults>b__6() at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass7.<GetResults>b__5() at System.Data.Entity.Infrastructure.DefaultExecutionStrategy.Execute[TResult](Func`1 operation) at System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) at System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0() at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext() at System.Linq.Buffer`1..ctor(IEnumerable`1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source) at _80707.UnitTest1.TestMethod1() in d:\Projects\80707\80707\UnitTest1.cs:line 29
[12 Jun 2016 20:43]
Michael Joseph
I am getting the same error. The problem seems to be with the OrderBy lambda expression. Below is the code that gives me the error. However, if I comment out the line with the OrderBy, everything works. This is a somewhat big problem for us because we want to implement paging in our API, which makes use of the .Take() and .Skip() LINQ operators. Howerver, the Take() and Skip() operators only work on a sorted result set (given to us by an OrderBy). public IList<Document> Post(SearchDocumentsCriteria sc, int pageIndex = 0, int pageSize = 5) { using (var db = new MyDbContext()) { var query = from q in db.Documents select q; if (sc.IsLocked != Code.BooleanFilter.Any) { query = query.Where(x => x.IsLocked == (sc.IsLocked == Code.BooleanFilter.Yes)); } if (sc.IsProcessed != Code.BooleanFilter.Any) { query = query.Where(x => x.IsProcessed == (sc.IsProcessed == Code.BooleanFilter.Yes)); } if (sc.Type.HasValue) { query = query.Where(x => x.DocumentTypeId == sc.Type); } var results = query .OrderBy(x => x.DocumentId) //.Skip(1) //.Take(1) .ToList(); return results; } }
[5 Apr 2017 16:29]
John Muller
Not 100% if this is applicable, the downloadable source code's Accept method on CaseFragment (SqlFragment.cs) starts with: Else.Accept(visitor); // line approximately 284 and 5 lines later: if(Else != null) Else.Accept(visitor); My question - duplication? And what happened to the if on the first line? Checked on 7.0.7