-
Notifications
You must be signed in to change notification settings - Fork 161
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
Fix duplicate JOIN statements when expanding an IQueryable that already has a join #1040
base: release-8.x
Are you sure you want to change the base?
Fix duplicate JOIN statements when expanding an IQueryable that already has a join #1040
Conversation
src/Microsoft.AspNetCore.OData/Query/Expressions/SelectExpandBinder.cs
Outdated
Show resolved
Hide resolved
} | ||
else if (isSourceNullable) | ||
{ | ||
object defaultValue = prop.PropertyType.IsValueType ? Activator.CreateInstance(prop.PropertyType) : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about if the property type doesn't have the default constructor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All value types have a default constructor. So I don't think there will ever be a case where the property type does not have a default constructor. https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/types#833-default-constructors
src/Microsoft.AspNetCore.OData/Query/Expressions/SelectExpandBinder.cs
Outdated
Show resolved
Hide resolved
test/Microsoft.AspNetCore.OData.Tests/Query/Expressions/SelectExpandBinderTest.cs
Show resolved
Hide resolved
3409e83
to
425c828
Compare
foreach (var sp in structuralProperties) | ||
{ | ||
if (prop.CanWrite && model.GetClrPropertyName(sp) == prop.Name) | ||
{ | ||
MemberExpression propertyExpression = Expression.Property(source, prop); | ||
bindings.Add(Expression.Bind(prop, propertyExpression)); | ||
Expression propertyValue = Expression.Property(source, prop); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we create a test case to test a big schema, for example, more than 1k properties for an entity type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to have an entity type with more than 1k properties?
da83272
to
d504172
Compare
Orders = new List<QueryOrder>() | ||
}; | ||
|
||
QueryOrder order1 = new QueryOrder { Id = 42, Title = "The order", Customer = customer1 }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let us stick to var for consistency.
@@ -82,7 +84,19 @@ public SelectExpandBinderTest() | |||
QueryOrder order = new QueryOrder { Id = 42, Title = "The order", Customer = customer }; | |||
customer.Orders.Add(order); | |||
|
|||
QueryCustomer customer1 = new QueryCustomer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let us stick to var for consistency.
// as observed here: https://github.com/OData/AspNetCoreOData/issues/497 | ||
|
||
Expression updatedExpression = null; | ||
if (IsEfQueryProvider(context)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var updatedExpression = source;
if (IsEfQueryProvider(context))
{
updatedExpression = RemoveNonStructuralProperties(context, source, structuredType);
}
Fixes #1035
In this fix #993 we added a fix to remove duplicate joins from the generated sql. This involved making updates to the Instance property of the expression to be created and only including structural properties.
The changes led to this being generated:
Instead of this:
These changes did not take into consideration query settings. I've added checks for nullability and handling null propagation and creating a conditional expression.