Skip to content
Merged
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
6 changes: 3 additions & 3 deletions src/NHibernate.Test/Async/Hql/EntityJoinHqlTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,9 @@ public async Task NullableEntityProjectionAsync()
var withNullManyToOneList = await (session.Query<NullableOwner>().Where(x => x.ManyToOne == null).ToListAsync());
var withNullManyToOneJoinedList =
await ((from x in session.Query<NullableOwner>()
from x2 in session.Query<NullableOwner>()
where x == x2 && x.ManyToOne == null && x.OneToOne.Name == null
select x2).ToListAsync());
from x2 in session.Query<NullableOwner>()
where x == x2 && x.ManyToOne == null && x.OneToOne.Name == null
select x2).ToListAsync());
Comment on lines -349 to +351
Copy link
Member Author

@fredericDelaporte fredericDelaporte Nov 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure why those changes occur. Let's get rid of them, if that is not an unstable generation artifact.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I just made some whitespace changes for #2772 and forgot to regenerate async code.

Assert.That(fullList.Count, Is.EqualTo(2));
Assert.That(withValidManyToOneList.Count, Is.EqualTo(0));
Assert.That(withValidManyToOneList2.Count, Is.EqualTo(0));
Expand Down
28 changes: 23 additions & 5 deletions src/NHibernate.Test/Linq/TryGetMappedTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,19 @@ public void NestedComponentPropertyCastTest()
o => o?.Name == "component[OtherProperty1]");
}

[Test(Description = "GH-2937")]
public void CompositeUserTypePropertyTest()
{
var query = session.Query<Glarch>().Select(o => o.Multiple.count);
AssertSupported(
query,
typeof(Glarch).FullName,
"Multiple.count",
o => o is Int32Type,
o => o?.Name == typeof(MultiplicityType).FullName,
null);
}

[Test]
public void ManyToOneTest()
{
Expand Down Expand Up @@ -723,9 +736,10 @@ private void AssertSupported(
string expectedEntityName,
string expectedMemberPath,
Predicate<IType> expectedMemberType,
Predicate<IAbstractComponentType> expectedComponentType = null)
Predicate<IAbstractComponentType> expectedComponentType = null,
bool? nullability = true)
{
AssertResult(query, true, true, expectedEntityName, expectedMemberPath, expectedMemberType, expectedComponentType);
AssertResult(query, true, true, expectedEntityName, expectedMemberPath, expectedMemberType, expectedComponentType, nullability);
}

private void AssertSupported(
Expand Down Expand Up @@ -768,7 +782,7 @@ private void AssertResult(
string expectedMemberPath,
Predicate<IType> expectedMemberType,
Predicate<IAbstractComponentType> expectedComponentType = null,
bool nullability = true)
bool? nullability = true)
{
expectedComponentType = expectedComponentType ?? (o => o == null);

Expand Down Expand Up @@ -809,8 +823,12 @@ private void AssertResult(

if (found)
{
Assert.That(_tryGetMappedNullability(Sfi, queryModel.SelectClause.Selector, out var isNullable), Is.True, "Expression should be supported");
Assert.That(nullability, Is.EqualTo(isNullable), "Nullability is not correct");
Assert.That(
_tryGetMappedNullability(Sfi, queryModel.SelectClause.Selector, out var isNullable),
Is.EqualTo(nullability.HasValue),
$"Expression should be {(nullability.HasValue ? "supported" : "unsupported")}");
if (nullability.HasValue)
Assert.That(nullability, Is.EqualTo(isNullable), "Nullability is not correct");
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion src/NHibernate/Util/ExpressionsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,17 @@ internal static bool TryGetMappedNullability(
int index;
if (componentType != null)
{
var propertyNullability = componentType.PropertyNullability;
if (propertyNullability == null)
{
nullable = false;
return false;
}

index = Array.IndexOf(
componentType.PropertyNames,
memberPath.Substring(memberPath.LastIndexOf('.') + 1));
nullable = componentType.PropertyNullability[index];
nullable = propertyNullability[index];
return true;
}

Expand Down