Skip to content

Commit 2b2cbdb

Browse files
committed
Revert the related fix in 5.5.0
1 parent a51b3e2 commit 2b2cbdb

5 files changed

Lines changed: 6 additions & 73 deletions

File tree

OData/src/System.Web.OData/Extensions/HttpRequestMessageProperties.cs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ public class HttpRequestMessageProperties
3333
private const string RoutingConventionsKey = "System.Web.OData.RoutingConventions";
3434
private const string SelectExpandClauseKey = "System.Web.OData.SelectExpandClause";
3535
private const string TotalCountKey = "System.Web.OData.TotalCount";
36-
private const string TotalCountFuncKey = "System.Web.OData.TotalCountFunc";
3736

3837
internal const string ODataServiceVersionHeader = "OData-Version";
3938
internal const string ODataMaxServiceVersionHeader = "OData-MaxVersion";
@@ -48,24 +47,6 @@ internal HttpRequestMessageProperties(HttpRequestMessage request)
4847
_request = request;
4948
}
5049

51-
internal Func<long> TotalCountFunc
52-
{
53-
get
54-
{
55-
object totalCountFunc;
56-
if (_request.Properties.TryGetValue(TotalCountFuncKey, out totalCountFunc))
57-
{
58-
return (Func<long>)totalCountFunc;
59-
}
60-
61-
return null;
62-
}
63-
set
64-
{
65-
_request.Properties[TotalCountFuncKey] = value;
66-
}
67-
}
68-
6950
/// <summary>
7051
/// Gets or sets the EDM model associated with the request.
7152
/// </summary>
@@ -165,11 +146,6 @@ public long? TotalCount
165146
return (long)totalCount;
166147
}
167148

168-
if (this.TotalCountFunc != null)
169-
{
170-
return this.TotalCountFunc();
171-
}
172-
173149
return null;
174150
}
175151
set

OData/src/System.Web.OData/OData/ExpressionHelpers.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ namespace System.Web.OData
1313
{
1414
internal static class ExpressionHelpers
1515
{
16-
public static Func<long> Count(IQueryable query, Type type)
16+
public static long Count(IQueryable query, Type type)
1717
{
1818
MethodInfo countMethod = ExpressionHelperMethods.QueryableCountGeneric.MakeGenericMethod(type);
19-
Expression<Func<long>> func = Expression.Lambda<Func<long>>(Expression.Call(null, countMethod, query.Expression));
20-
return func.Compile();
19+
return (long)countMethod.Invoke(null, new object[] { query });
2120
}
2221

2322
public static IQueryable Skip(IQueryable query, int count, Type type, bool parameterize)

OData/src/System.Web.OData/OData/Query/CountQueryOption.cs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -135,28 +135,6 @@ public void Validate(ODataValidationSettings validationSettings)
135135
throw Error.NotSupported(SRResources.ApplyToOnUntypedQueryOption, "GetEntityCount");
136136
}
137137

138-
if (Value)
139-
{
140-
return ExpressionHelpers.Count(query, Context.ElementClrType)();
141-
}
142-
else
143-
{
144-
return null;
145-
}
146-
}
147-
148-
/// <summary>
149-
/// Gets the Func of entities number that satisfy the given query if the response should include a count query option, or <c>null</c> otherwise.
150-
/// </summary>
151-
/// <param name="query">The query to compute the count for.</param>
152-
/// <returns>The the Func of entities number that satisfy the specified query if the response should include a count query option, or <c>null</c> otherwise.</returns>
153-
internal Func<long> GetEntityCountFunc(IQueryable query)
154-
{
155-
if (Context.ElementClrType == null)
156-
{
157-
throw Error.NotSupported(SRResources.ApplyToOnUntypedQueryOption, "GetEntityCount");
158-
}
159-
160138
if (Value)
161139
{
162140
return ExpressionHelpers.Count(query, Context.ElementClrType);

OData/src/System.Web.OData/OData/Query/ODataQueryOptions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,12 @@ public virtual IQueryable ApplyTo(IQueryable query, ODataQuerySettings querySett
261261

262262
if (Count != null)
263263
{
264-
if (Request.ODataProperties().TotalCountFunc == null)
264+
if (Request.ODataProperties().TotalCount == null)
265265
{
266-
Func<long> countFunc = Count.GetEntityCountFunc(result);
267-
if (countFunc != null)
266+
long? count = Count.GetEntityCount(result);
267+
if (count.HasValue)
268268
{
269-
Request.ODataProperties().TotalCountFunc = countFunc;
269+
Request.ODataProperties().TotalCount = count.Value;
270270
}
271271
}
272272

OData/test/System.Web.OData.Test/OData/Query/CountQueryOptionTest.cs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -133,26 +133,6 @@ public void GetEntityCount_ReturnsNull_IfValueIsFalse()
133133
Assert.Null(countOption.GetEntityCount(_customers));
134134
}
135135

136-
[Fact]
137-
public void GetEntityCountFunc_ReturnsFunc_IfValueIsTrue()
138-
{
139-
// Arrange
140-
var countOption = new CountQueryOption("true", _context);
141-
142-
// Act & Assert
143-
Assert.Equal(3, countOption.GetEntityCountFunc(_customers)());
144-
}
145-
146-
[Fact]
147-
public void GetEntityCountFunc_ReturnsNull_IfValueIsFalse()
148-
{
149-
// Arrange
150-
var countOption = new CountQueryOption("false", _context);
151-
152-
// Act & Assert
153-
Assert.Null(countOption.GetEntityCountFunc(_customers));
154-
}
155-
156136
[Fact]
157137
public void Property_Value_WorksWithUnTypedContext()
158138
{

0 commit comments

Comments
 (0)