-
Notifications
You must be signed in to change notification settings - Fork 934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NRE with nullable subselect value in Linq #2425
Comments
This issue should be fixed by #2079, where a friendlier exception is thrown when the cast is missing: nhibernate-core/src/NHibernate.Test/Linq/SelectionTests.cs Lines 1057 to 1081 in 04e4093
In order to assure that the issue is fixed by the mentioned PR, it would be nice if you provide the whole linq query so that it can be added to the tests. |
I reproduced this issue on master branch nhibernate |
The mentioned PR is not yet merged into master, you need to build the code from the PR in order to test it. |
[Test]
public void CanExecuteMethodWithNullObjectAndSubselect()
{
var list1 = db.Animals.Select(
a => new
{
NullableId = (int?) a.Father.Father.Id,
})
.ToList();
Assert.That(list1, Has.Count.GreaterThan(0));
Assert.That(list1[0].NullableId, Is.Null);
var list2 = db.Animals.Select(
a => new
{
Descriptions = a.Children.Select(z => z.Description)
})
.ToList();
Assert.That(list2, Has.Count.GreaterThan(0));
Assert.That(list2[0].Descriptions, Is.Not.Null);
var list3 = db.Animals.Select(
a => new
{
NullableId = (int?) a.Father.Father.Id,
Descriptions = a.Children.Select(z=>z.Description)
})
.ToList();
Assert.That(list3, Has.Count.GreaterThan(0));
Assert.That(list3[0].NullableId, Is.Null);
Assert.That(list3[0].Descriptions, Is.Not.Null);
} NHibernate.Exceptions.GenericADOException : Could not execute query[SQL: SQL not available]
----> System.NullReferenceException : Object reference not set to an instance of an object.
at NHibernate.Impl.SessionImpl.List(IQueryExpression queryExpression, QueryParameters queryParameters, IList results, Object filterConnection) in r:\nhibernate-core-GH2054\src\NHibernate\Impl\SessionImpl.cs:line 560
at NHibernate.Impl.SessionImpl.List(IQueryExpression queryExpression, QueryParameters queryParameters, IList results) in r:\nhibernate-core-GH2054\src\NHibernate\Impl\SessionImpl.cs:line 520
at NHibernate.Impl.AbstractSessionImpl.List[T](IQueryExpression query, QueryParameters parameters) in r:\nhibernate-core-GH2054\src\NHibernate\Impl\AbstractSessionImpl.cs:line 150
at NHibernate.Impl.AbstractQueryImpl2.List[T]() in r:\nhibernate-core-GH2054\src\NHibernate\Impl\AbstractQueryImpl2.cs:line 111
at NHibernate.Linq.DefaultQueryProvider.ExecuteList[TResult](Expression expression) in r:\nhibernate-core-GH2054\src\NHibernate\Linq\DefaultQueryProvider.cs:line 111
at NHibernate.Linq.NhQueryable`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() in r:\nhibernate-core-GH2054\src\NHibernate\Linq\NhQueryable.cs:line 65
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at NHibernate.Test.Linq.SelectionTests.CanExecuteMethodWithNullObjectAndSubselect() in r:\nhibernate-core-GH2054\src\NHibernate.Test\Linq\SelectionTests.cs:line 1167
--NullReferenceException
at lambda_method(Closure , IGrouping`2 )
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at NHibernate.Linq.ResultTransformer.TransformList(IList collection) in r:\nhibernate-core-GH2054\src\NHibernate\Linq\ResultTransformer.cs:line 36
at NHibernate.Loader.Hql.QueryLoader.GetResultList(IList results, IResultTransformer resultTransformer) in r:\nhibernate-core-GH2054\src\NHibernate\Loader\Hql\QueryLoader.cs:line 343
at NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters) in r:\nhibernate-core-GH2054\src\NHibernate\Loader\Loader.cs:line 1837
at NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet`1 querySpaces) in r:\nhibernate-core-GH2054\src\NHibernate\Loader\Loader.cs:line 1827
at NHibernate.Loader.Hql.QueryLoader.List(ISessionImplementor session, QueryParameters queryParameters) in r:\nhibernate-core-GH2054\src\NHibernate\Loader\Hql\QueryLoader.cs:line 325
at NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.List(ISessionImplementor session, QueryParameters queryParameters) in r:\nhibernate-core-GH2054\src\NHibernate\Hql\Ast\ANTLR\QueryTranslatorImpl.cs:line 131
at NHibernate.Engine.Query.HQLQueryPlan.PerformList(QueryParameters queryParameters, ISessionImplementor session, IList results) in r:\nhibernate-core-GH2054\src\NHibernate\Engine\Query\HQLQueryPlan.cs:line 115
at NHibernate.Impl.SessionImpl.List(IQueryExpression queryExpression, QueryParameters queryParameters, IList results, Object filterConnection) in r:\nhibernate-core-GH2054\src\NHibernate\Impl\SessionImpl.cs:line 550 |
Thanks for providing the test case, I made a fix in #2428. |
Version: NHibernate-5.3.0
Exception:
Object reference not set to an instance of an object.
LINQ Expression:
listTransformers[1].ToString()
Exception happened only if Select contains "Subselect" and any value "pass" through null value
The text was updated successfully, but these errors were encountered: