Skip to content

Fix some Contains subqueries failures with Linq #3212

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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/NetCoreTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:

- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v2
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x

Expand Down
1 change: 1 addition & 0 deletions src/NHibernate.Test/Async/Linq/ByMethod/MappedAsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public async Task WithUnaryExpressionAsync()
await (db.Orders.Where(o => o.Freight == (-num).MappedAs(NHibernateUtil.Decimal)).ToListAsync());
await (db.Orders.Where(o => o.Freight == ((decimal) num).MappedAs(NHibernateUtil.Decimal)).ToListAsync());
await (db.Orders.Where(o => o.Freight == ((decimal?) (decimal) num).MappedAs(NHibernateUtil.Decimal)).ToListAsync());
await (db.Orders.Where(o => db.Orders.Where(o2 => o2.Freight == (-num).MappedAs(NHibernateUtil.Decimal)).Contains(o)).ToListAsync());
}

[Test]
Expand Down
1 change: 1 addition & 0 deletions src/NHibernate.Test/Linq/ByMethod/MappedAsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public void WithUnaryExpression()
db.Orders.Where(o => o.Freight == (-num).MappedAs(NHibernateUtil.Decimal)).ToList();
db.Orders.Where(o => o.Freight == ((decimal) num).MappedAs(NHibernateUtil.Decimal)).ToList();
db.Orders.Where(o => o.Freight == ((decimal?) (decimal) num).MappedAs(NHibernateUtil.Decimal)).ToList();
db.Orders.Where(o => db.Orders.Where(o2 => o2.Freight == (-num).MappedAs(NHibernateUtil.Decimal)).Contains(o)).ToList();
}

[Test]
Expand Down
10 changes: 10 additions & 0 deletions src/NHibernate.Test/Linq/ParameterTypeLocatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,16 @@ public void ContainsStringEnumTest()
db.Users.Where(o => values.Contains(o.Name == o.Name ? o.Enum1 : o.NullableEnum1.Value)),
db.Timesheets.Where(o => o.Users.Any(u => values.Contains(u.Enum1)))
);

AssertResults(
new Dictionary<string, Predicate<IType>>
{
{"0", o => o is Int32Type},
{"value(NHibernate.DomainModel.Northwind.Entities.EnumStoredAsString[])", o => o is EnumStoredAsStringType}
},
db.Timesheets.Where(o => o.Users.Where(u => u.Id > 0).Any(u => values.Contains(u.Enum1))),
db.Timesheets.Where(o => o.Users.Any(u => u.Id > 0 && values.Contains(u.Enum1)))
);
}

[Test]
Expand Down
1 change: 1 addition & 0 deletions src/NHibernate/Linq/Visitors/ParameterTypeLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ private bool TryLinkContainsMethod(QueryModel queryModel)
// ContainsResultOperator where the constant expression is dislocated from the related expression,
// we have to manually link the related expressions.
if (queryModel.ResultOperators.Count != 1 ||
queryModel.BodyClauses.Count > 0 ||
!(queryModel.ResultOperators[0] is ContainsResultOperator containsOperator) ||
!(queryModel.SelectClause.Selector is QuerySourceReferenceExpression querySourceReference) ||
!(querySourceReference.ReferencedQuerySource is MainFromClause mainFromClause))
Expand Down