Skip to content

Commit dab67f1

Browse files
committed
Reaction on feedback
1 parent a664c12 commit dab67f1

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/Microsoft.AspNet.OData.Shared/Query/Expressions/AggregationBinder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,10 +495,10 @@ private Expression CreatePropertyAggregateExpression(ParameterExpression accum,
495495

496496
private Expression WrapConvert(Expression expression)
497497
{
498-
// Expression that we are generating looks like Value = $it.PropertyName where Value is defined as object, but PropertyName can be any type
499-
// Proper .NET expression must look like as Value = (object) $it.PropertyName or AccessViolationExceptino will be thrown
498+
// Expression that we are generating looks like Value = $it.PropertyName where Value is defined as object and PropertyName can be value
499+
// Proper .NET expression must look like as Value = (object) $it.PropertyName for proper boxing or AccessViolationException will be thrown
500500
// Cast to object isn't translatable by EF6 as a result skipping (object) in that case
501-
return this._classicEF
501+
return (this._classicEF || !expression.Type.IsValueType)
502502
? expression
503503
: Expression.Convert(expression, typeof(object));
504504
}

test/E2ETest/Microsoft.Test.E2E.AspNet.OData/Aggregation/AggregationContextCore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class AggregationContextCoreSql : AggregationContextCoreBase
2626
{
2727
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
2828
{
29-
optionsBuilder.UseSqlServer(@"Data Source=(LocalDb)\MSSQLLocalDB;Integrated Security=True;Persist Security Info = True;Database = AggregationTestCore1");
29+
optionsBuilder.UseSqlServer(@"Data Source=(LocalDb)\MSSQLLocalDB;Integrated Security=True;Persist Security Info = True;Database = AggregationEFCoreTest");
3030
base.OnConfiguring(optionsBuilder);
3131
}
3232
}

test/UnitTest/Microsoft.AspNet.OData.Test.Shared/Query/Expressions/AggregationBinderTests.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public void SingleGroupBy()
2828
{
2929
var filters = VerifyQueryDeserialization(
3030
"groupby((ProductName))",
31-
".GroupBy($it => new GroupByWrapper() {GroupByContainer = new LastInChain() {Name = ProductName, Value = Convert($it.ProductName), }, })"
31+
".GroupBy($it => new GroupByWrapper() {GroupByContainer = new LastInChain() {Name = ProductName, Value = $it.ProductName, }, })"
3232
+ ".Select($it => new AggregationWrapper() {GroupByContainer = $it.Key.GroupByContainer, })");
3333
}
3434

@@ -37,7 +37,7 @@ public void MultipleGroupBy()
3737
{
3838
var filters = VerifyQueryDeserialization(
3939
"groupby((ProductName, SupplierID))",
40-
".GroupBy($it => new GroupByWrapper() {GroupByContainer = new AggregationPropertyContainer() {Name = SupplierID, Value = Convert($it.SupplierID), Next = new LastInChain() {Name = ProductName, Value = Convert($it.ProductName), }, }, })"
40+
".GroupBy($it => new GroupByWrapper() {GroupByContainer = new AggregationPropertyContainer() {Name = SupplierID, Value = Convert($it.SupplierID), Next = new LastInChain() {Name = ProductName, Value = $it.ProductName, }, }, })"
4141
+ ".Select($it => new AggregationWrapper() {GroupByContainer = $it.Key.GroupByContainer, })");
4242
}
4343

@@ -46,7 +46,7 @@ public void NavigationGroupBy()
4646
{
4747
var filters = VerifyQueryDeserialization(
4848
"groupby((Category/CategoryName))",
49-
".GroupBy($it => new GroupByWrapper() {GroupByContainer = new NestedPropertyLastInChain() {Name = Category, NestedValue = new GroupByWrapper() {GroupByContainer = new LastInChain() {Name = CategoryName, Value = Convert($it.Category.CategoryName), }, }, }, })"
49+
".GroupBy($it => new GroupByWrapper() {GroupByContainer = new NestedPropertyLastInChain() {Name = Category, NestedValue = new GroupByWrapper() {GroupByContainer = new LastInChain() {Name = CategoryName, Value = $it.Category.CategoryName, }, }, }, })"
5050
+ ".Select($it => new AggregationWrapper() {GroupByContainer = $it.Key.GroupByContainer, })");
5151
}
5252

@@ -55,7 +55,7 @@ public void NavigationMultipleGroupBy()
5555
{
5656
var filters = VerifyQueryDeserialization(
5757
"groupby((Category/CategoryName, SupplierAddress/State))",
58-
".GroupBy($it => new GroupByWrapper() {GroupByContainer = new NestedProperty() {Name = SupplierAddress, NestedValue = new GroupByWrapper() {GroupByContainer = new LastInChain() {Name = State, Value = Convert($it.SupplierAddress.State), }, }, Next = new NestedPropertyLastInChain() {Name = Category, NestedValue = new GroupByWrapper() {GroupByContainer = new LastInChain() {Name = CategoryName, Value = Convert($it.Category.CategoryName), }, }, }, }, })"
58+
".GroupBy($it => new GroupByWrapper() {GroupByContainer = new NestedProperty() {Name = SupplierAddress, NestedValue = new GroupByWrapper() {GroupByContainer = new LastInChain() {Name = State, Value = $it.SupplierAddress.State, }, }, Next = new NestedPropertyLastInChain() {Name = Category, NestedValue = new GroupByWrapper() {GroupByContainer = new LastInChain() {Name = CategoryName, Value = $it.Category.CategoryName, }, }, }, }, })"
5959
+ ".Select($it => new AggregationWrapper() {GroupByContainer = $it.Key.GroupByContainer, })");
6060
}
6161

@@ -64,7 +64,7 @@ public void SingleDynamicGroupBy()
6464
{
6565
var filters = VerifyQueryDeserialization<DynamicProduct>(
6666
"groupby((ProductProperty))",
67-
".GroupBy($it => new GroupByWrapper() {GroupByContainer = new LastInChain() {Name = ProductProperty, Value = Convert(IIF($it.ProductProperties.ContainsKey(ProductProperty), $it.ProductPropertiesProductProperty, null)), }, })"
67+
".GroupBy($it => new GroupByWrapper() {GroupByContainer = new LastInChain() {Name = ProductProperty, Value = IIF($it.ProductProperties.ContainsKey(ProductProperty), $it.ProductPropertiesProductProperty, null), }, })"
6868
+ ".Select($it => new AggregationWrapper() {GroupByContainer = $it.Key.GroupByContainer, })");
6969
}
7070

@@ -84,7 +84,7 @@ public void SingleDynamicSum()
8484
var filters = VerifyQueryDeserialization<DynamicProduct>(
8585
"aggregate(ProductProperty with sum as ProductProperty)",
8686
".GroupBy($it => new NoGroupByWrapper())"
87-
+ ".Select($it => new NoGroupByAggregationWrapper() {Container = new LastInChain() {Name = ProductProperty, Value = Convert(Convert(Convert($it).Sum($it => IIF($it.ProductProperties.ContainsKey(ProductProperty), $it.ProductPropertiesProductProperty, null).SafeConvertToDecimal()))), }, })");
87+
+ ".Select($it => new NoGroupByAggregationWrapper() {Container = new LastInChain() {Name = ProductProperty, Value = Convert(Convert($it).Sum($it => IIF($it.ProductProperties.ContainsKey(ProductProperty), $it.ProductPropertiesProductProperty, null).SafeConvertToDecimal())), }, })");
8888
}
8989

9090
[Fact]
@@ -102,7 +102,7 @@ public void SingleDynamicMin()
102102
var filters = VerifyQueryDeserialization<DynamicProduct>(
103103
"aggregate(ProductProperty with min as MinProductProperty)",
104104
".GroupBy($it => new NoGroupByWrapper())"
105-
+ ".Select($it => new NoGroupByAggregationWrapper() {Container = new LastInChain() {Name = MinProductProperty, Value = Convert(Convert($it).Min($it => IIF($it.ProductProperties.ContainsKey(ProductProperty), $it.ProductPropertiesProductProperty, null))), }, })");
105+
+ ".Select($it => new NoGroupByAggregationWrapper() {Container = new LastInChain() {Name = MinProductProperty, Value = Convert($it).Min($it => IIF($it.ProductProperties.ContainsKey(ProductProperty), $it.ProductPropertiesProductProperty, null)), }, })");
106106
}
107107

108108
[Fact]
@@ -146,7 +146,7 @@ public void GroupByAndAggregate()
146146
{
147147
var filters = VerifyQueryDeserialization(
148148
"groupby((ProductName), aggregate(SupplierID with sum as SupplierID))",
149-
".GroupBy($it => new GroupByWrapper() {GroupByContainer = new LastInChain() {Name = ProductName, Value = Convert($it.ProductName), }, })"
149+
".GroupBy($it => new GroupByWrapper() {GroupByContainer = new LastInChain() {Name = ProductName, Value = $it.ProductName, }, })"
150150
+ ".Select($it => new AggregationWrapper() {GroupByContainer = $it.Key.GroupByContainer, Container = new LastInChain() {Name = SupplierID, Value = Convert(Convert($it).Sum($it => $it.SupplierID)), }, })");
151151
}
152152

0 commit comments

Comments
 (0)