Skip to content

Commit 307fd8d

Browse files
nkreipkehazzik
authored andcommitted
NH-3665 - ProcessFirstOrSingleBase - use result type override if present in
1 parent 8590368 commit 307fd8d

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/NHibernate.Test/Linq/WhereTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,19 @@ public void CanUseCompareInQuery(Expression<Func<Product, bool>> expression, int
795795
}
796796

797797

798+
[Test(Description = "NH-3665")]
799+
public void SelectOnCollectionReturnsResult()
800+
{
801+
var result = db.Animals.Select(x => new
802+
{
803+
x.Children
804+
}).FirstOrDefault();
805+
806+
Assert.That(result, Is.Not.Null);
807+
Assert.That(result.Children, Is.Not.Empty);
808+
}
809+
810+
798811
private static List<object[]> CanUseCompareInQueryDataSource()
799812
{
800813
return new List<object[]>

src/NHibernate/Linq/Visitors/ResultOperatorProcessors/ProcessFirstOrSingleBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class ProcessFirstOrSingleBase
99
{
1010
protected static void AddClientSideEval(MethodInfo target, QueryModelVisitor queryModelVisitor, IntermediateHqlTree tree)
1111
{
12-
var type = queryModelVisitor.Model.SelectClause.Selector.Type;
12+
var type = queryModelVisitor.Model.ResultTypeOverride ?? queryModelVisitor.Model.SelectClause.Selector.Type;
1313
target = target.MakeGenericMethod(type);
1414

1515
var parameter = Expression.Parameter(typeof(IQueryable<>).MakeGenericType(type), null);

0 commit comments

Comments
 (0)