Skip to content

NRE with nullable subselect value in Linq #2425

Closed
@NikitaEgorov

Description

@NikitaEgorov

Version: NHibernate-5.3.0
Exception:
Object reference not set to an instance of an object.

   at System.Linq.Enumerable.SelectEnumerableIterator`2.ToList()
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at NHibernate.Linq.ResultTransformer.TransformList(IList collection) in r:\nhibernate-core-master\src\NHibernate\Linq\ResultTransformer.cs:line 36

LINQ Expression:

.Select(
    x => new
        {
            x.Date,
            x.Employee.Number,
            CountyNumber = (int?)x.Site.CountyNumber, <=== Pass through null value
            Item = x.Items.Select(zx => new { zx.Value }) <=== Subselect
        })

listTransformers[1].ToString()

inputList => inputList
    .Select(g => new <>f__AnonymousType1`4(
                Date = Convert(g.Key.Items[1], Nullable`1), 
                Number = Convert(g.Key.Items[2], Int32), 
                CountyNumber = Convert(Convert(g.Key.Items[3], Int32), Nullable`1), <======== Int32 shoud be Nullable
                Item = Convert(g.Where(t => Not(ReferenceEquals(t.Items[0], null))).Select(value => new <>f__AnonymousType2`1(BaseValue = Convert(value.Items[1], Nullable`1))).ToList().AsReadOnly(), IEnumerable`1))).ToList()

Exception happened only if Select contains "Subselect" and any value "pass" through null value

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions