Skip to content

Commit 651b579

Browse files
Minimize the use of IQueryable generic parameter (#414)
1 parent 42bb59a commit 651b579

19 files changed

Lines changed: 102 additions & 86 deletions

net/DevExtreme.AspNet.Data.Tests/Compat.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ public static string ExpectedConvert(object subj, string type) {
1717
return text.Append(")").ToString();
1818
}
1919

20-
public static DataSourceExpressionBuilder<T> CreateDataSourceExpressionBuilder<T>(DataSourceLoadOptionsBase options) {
20+
public static DataSourceExpressionBuilder CreateDataSourceExpressionBuilder<T>(DataSourceLoadOptionsBase options) {
2121
var source = new EnumerableQuery<T>(Expression.Parameter(typeof(IQueryable<T>), "data"));
2222
return CreateDataSourceExpressionBuilder(source, options);
2323
}
2424

25-
public static DataSourceExpressionBuilder<T> CreateDataSourceExpressionBuilder<T>(IQueryable<T> source, DataSourceLoadOptionsBase options) {
26-
return new DataSourceExpressionBuilder<T>(
25+
public static DataSourceExpressionBuilder CreateDataSourceExpressionBuilder<T>(IQueryable<T> source, DataSourceLoadOptionsBase options) {
26+
return new DataSourceExpressionBuilder(
2727
source.Expression,
2828
new DataSourceLoadContext(
2929
options,

net/DevExtreme.AspNet.Data.Tests/DynamicBindingTests.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ public void Issue227() {
215215

216216
[Fact]
217217
public void NoToStringForNumbers() {
218-
var compiler = new FilterExpressionCompiler<dynamic>(false);
218+
var compiler = new FilterExpressionCompiler(typeof(object), false);
219219

220220
void Case(IList clientFilter, string expectedExpr, object trueTestValue) {
221221
var expr = compiler.Compile(clientFilter);
@@ -270,6 +270,22 @@ public void T819075() {
270270
RequireTotalCount = true
271271
}).totalCount);
272272
}
273+
274+
[Fact]
275+
public void Issue413() {
276+
// https://github.com/DevExpress/DevExtreme.AspNet.Data/issues/413#issuecomment-580766581
277+
278+
IQueryable<object> projection = new[] { new { A = 1 } }
279+
.AsQueryable()
280+
.Select(i => new { i.A });
281+
282+
var loadResult = DataSourceLoader.Load(projection, new SampleLoadOptions {
283+
Filter = new[] { "A", "1" },
284+
RequireTotalCount = true
285+
});
286+
287+
Assert.Equal(1, loadResult.totalCount);
288+
}
273289
}
274290

275291
}

net/DevExtreme.AspNet.Data.Tests/ExpressionCompilerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class ExpressionCompilerTests {
1212
class SampleCompiler : ExpressionCompiler {
1313

1414
public SampleCompiler(bool guardNulls)
15-
: base(guardNulls) {
15+
: base(null, guardNulls) {
1616
}
1717

1818
}

net/DevExtreme.AspNet.Data.Tests/Extensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
namespace DevExtreme.AspNet.Data.Tests {
55

66
static class Extensions {
7-
public static Expression BuildLoadExpr<T>(this DataSourceExpressionBuilder<T> builder) => builder.BuildLoadExpr(true);
8-
public static Expression BuildLoadGroupsExpr<T>(this DataSourceExpressionBuilder<T> builder) => builder.BuildLoadGroupsExpr(false);
7+
public static Expression BuildLoadExpr(this DataSourceExpressionBuilder builder) => builder.BuildLoadExpr(true);
8+
public static Expression BuildLoadGroupsExpr(this DataSourceExpressionBuilder builder) => builder.BuildLoadGroupsExpr(false);
99
}
1010

1111
}

net/DevExtreme.AspNet.Data.Tests/FilterExpressionCompilerTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class DataItem1 {
1919
}
2020

2121
LambdaExpression Compile<T>(IList criteria, bool guardNulls = false) {
22-
return new FilterExpressionCompiler<T>(guardNulls).Compile(criteria);
22+
return new FilterExpressionCompiler(typeof(T), guardNulls).Compile(criteria);
2323
}
2424

2525
[Fact]
@@ -145,7 +145,7 @@ public void Not() {
145145
[Fact]
146146
public void IsUnaryWithJsonCriteria() {
147147
var crit = JsonConvert.DeserializeObject<IList>("[\"!\", []]");
148-
var compiler = new FilterExpressionCompiler<object>(false);
148+
var compiler = new FilterExpressionCompiler(typeof(object), false);
149149
Assert.True(compiler.IsUnary(crit));
150150
}
151151

net/DevExtreme.AspNet.Data.Tests/FilterExpressionCompilerTypeConversionTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class FilterExpressionCompilerTypeConversionTests {
1010
const string TEST_GUID = "01234567-0123-0123-0123-012345670000";
1111

1212
void AssertEvaluation<T>(T dataItem, params object[] clientFilter) {
13-
var expr = new FilterExpressionCompiler<T>(false).Compile(clientFilter);
13+
var expr = new FilterExpressionCompiler(typeof(T), false).Compile(clientFilter);
1414
Assert.True((bool)expr.Compile().DynamicInvoke(dataItem));
1515
}
1616

@@ -161,7 +161,7 @@ public void IntegralFromFloatString() {
161161

162162
[Fact]
163163
public void InvalidValueHandling() {
164-
var compiler = new FilterExpressionCompiler<Structs>(false);
164+
var compiler = new FilterExpressionCompiler(typeof(Structs), false);
165165

166166
Assert.Equal("False", compiler.Compile(new[] { "byte", "-3" }).Body.ToString());
167167
Assert.Equal("False", compiler.Compile(new[] { "byte", "257" }).Body.ToString());

net/DevExtreme.AspNet.Data.Tests/RemoteGroupExpressionCompilerTests.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ static ParameterExpression CreateTargetParam<T>() {
2424

2525
[Fact]
2626
public void Compile() {
27-
var compiler = new RemoteGroupExpressionCompiler<DataItem>(
27+
var compiler = new RemoteGroupExpressionCompiler(
28+
typeof(DataItem),
2829
new[] {
2930
new GroupingInfo { Selector = "G1" },
3031
new GroupingInfo { Selector = "G2", Desc = true }
@@ -83,7 +84,7 @@ public void Compile() {
8384

8485
[Fact]
8586
public void CompileEmpty() {
86-
var expr = new RemoteGroupExpressionCompiler<DataItem>(null, null, null).Compile(CreateTargetParam<DataItem>());
87+
var expr = new RemoteGroupExpressionCompiler(typeof(DataItem), null, null, null).Compile(CreateTargetParam<DataItem>());
8788
Assert.Equal(
8889
"data"
8990
+ ".GroupBy(obj => new AnonType())"
@@ -94,7 +95,7 @@ public void CompileEmpty() {
9495

9596
[Fact]
9697
public void IgnoreGroupSummaryIfNoGroups() {
97-
var compiler = new RemoteGroupExpressionCompiler<DataItem>(null, null, new[] {
98+
var compiler = new RemoteGroupExpressionCompiler(typeof(DataItem), null, null, new[] {
9899
new SummaryInfo { Selector = "ignore me", SummaryType = "ignore me" }
99100
});
100101

@@ -105,8 +106,8 @@ public void IgnoreGroupSummaryIfNoGroups() {
105106
public void GroupInterval_Numeric() {
106107

107108
string Compile<T>(string selector, bool guardNulls) {
108-
var compiler = new RemoteGroupExpressionCompiler<T>(
109-
guardNulls, false, null,
109+
var compiler = new RemoteGroupExpressionCompiler(
110+
typeof(T), guardNulls, false, null,
110111
new[] {
111112
new GroupingInfo { Selector = selector, GroupInterval = "123" }
112113
},
@@ -129,8 +130,8 @@ string Compile<T>(string selector, bool guardNulls) {
129130
public void GroupInterval_Date() {
130131

131132
string Compile<T>(string selector, bool guardNulls) {
132-
var compiler = new RemoteGroupExpressionCompiler<T>(
133-
guardNulls, false, null,
133+
var compiler = new RemoteGroupExpressionCompiler(
134+
typeof(T), guardNulls, false, null,
134135
new[] {
135136
new GroupingInfo { Selector = selector, GroupInterval = "year" },
136137
new GroupingInfo { Selector = selector, GroupInterval = "quarter" },
@@ -204,7 +205,8 @@ public void Bug100() {
204205
}
205206

206207
void Bug100Core<T>(params string[] memberNames) {
207-
var compiler = new RemoteGroupExpressionCompiler<T>(
208+
var compiler = new RemoteGroupExpressionCompiler(
209+
typeof(T),
208210
memberNames.Select(i => new GroupingInfo { Selector = i }).ToArray(),
209211
null,
210212
null
@@ -218,7 +220,7 @@ void Bug100Core<T>(params string[] memberNames) {
218220

219221
[Fact]
220222
public void GetSumType_ExpandFalse() {
221-
Type GetSumType<T>() => RemoteGroupExpressionCompiler<object>.GetSumType(typeof(T), false);
223+
Type GetSumType<T>() => RemoteGroupExpressionCompiler.GetSumType(typeof(T), false);
222224

223225
// Validation: check lambda type in new T[0].Sum(i => i)
224226

@@ -241,7 +243,7 @@ public void GetSumType_ExpandFalse() {
241243

242244
[Fact]
243245
public void GetSumType_ExpandTrue() {
244-
Type GetSumType<T>() => RemoteGroupExpressionCompiler<object>.GetSumType(typeof(T), true);
246+
Type GetSumType<T>() => RemoteGroupExpressionCompiler.GetSumType(typeof(T), true);
245247

246248
// Don't convert integer types to decimal because SQL decimals have variable precision
247249
// Except for UInt64 for which there is no better choice

net/DevExtreme.AspNet.Data.Tests/SelectExpressionCompilerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace DevExtreme.AspNet.Data.Tests {
1010
public class SelectExpressionCompilerTests {
1111

1212
Expression Compile<T>(params string[] selectors) {
13-
return new SelectExpressionCompiler<T>(false).Compile(
13+
return new SelectExpressionCompiler(typeof(T), false).Compile(
1414
Expression.Parameter(typeof(IQueryable<T>), "data"),
1515
selectors
1616
);

net/DevExtreme.AspNet.Data.Tests/SortExpressionCompilerTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace DevExtreme.AspNet.Data.Tests {
1010

1111
public class SortExpressionCompilerTests {
12-
SortExpressionCompiler<DataItem1> _compiler;
12+
SortExpressionCompiler _compiler;
1313
Expression _targetExpr;
1414

1515
class DataItem1 {
@@ -22,7 +22,7 @@ class DataItem2 {
2222
}
2323

2424
public SortExpressionCompilerTests() {
25-
_compiler = new SortExpressionCompiler<DataItem1>(false);
25+
_compiler = new SortExpressionCompiler(typeof(DataItem1), false);
2626
_targetExpr = Expression.Parameter(typeof(IQueryable<DataItem1>), "data");
2727
}
2828

@@ -91,7 +91,7 @@ public void SortByNestedProp() {
9191
};
9292

9393
var targetExpr = Expression.Parameter(typeof(IQueryable<DataItem2>), "data");
94-
var expr = new SortExpressionCompiler<DataItem2>(false).Compile(targetExpr, clientExpr);
94+
var expr = new SortExpressionCompiler(typeof(DataItem2), false).Compile(targetExpr, clientExpr);
9595
Assert.Equal("data.OrderBy(obj => obj.Inner.Prop1)", expr.ToString());
9696
}
9797

net/DevExtreme.AspNet.Data.Tests/StringToLowerTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void ForceToString_ToLower_GuardNulls() {
5353

5454
[Fact]
5555
public void Dynamic() {
56-
var compiler = new FilterExpressionCompiler<dynamic>(true, true);
56+
var compiler = new FilterExpressionCompiler(typeof(object), true, true);
5757
var expr = compiler.Compile(new object[] {
5858
new[] { "this", "startswith", "1" },
5959
"or",
@@ -97,7 +97,7 @@ void AssertFilter<T>(bool guardNulls, bool stringToLower, string op, string expe
9797

9898
Assert.Equal(
9999
expectedExpr,
100-
new FilterExpressionCompiler<T>(guardNulls, stringToLower)
100+
new FilterExpressionCompiler(typeof(T), guardNulls, stringToLower)
101101
.Compile(new[] { "this", op, "T" })
102102
.Body.ToString()
103103
);

0 commit comments

Comments
 (0)