Skip to content
This repository was archived by the owner on Jul 1, 2025. It is now read-only.
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ x64/
*.Publish.xml

Kendo.DynamicLinq.*.nupkg
/.vs/Kendo.DynamicLinq/v15/Server/sqlite3
/.vs
19 changes: 14 additions & 5 deletions Kendo.DynamicLinq.Tests/Kendo.DynamicLinq.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\NUnit3TestAdapter.3.9.0\build\net35\NUnit3TestAdapter.props" Condition="Exists('..\packages\NUnit3TestAdapter.3.9.0\build\net35\NUnit3TestAdapter.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand All @@ -12,6 +13,8 @@
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -31,8 +34,8 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit.2.6.3\lib\nunit.framework.dll</HintPath>
<Reference Include="nunit.framework, Version=3.9.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.9.0\lib\net40\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -47,9 +50,6 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SerializationTests.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
Expand All @@ -59,7 +59,16 @@
<Name>Kendo.DynamicLinq</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\NUnit3TestAdapter.3.9.0\build\net35\NUnit3TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit3TestAdapter.3.9.0\build\net35\NUnit3TestAdapter.props'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
4 changes: 2 additions & 2 deletions Kendo.DynamicLinq.Tests/SerializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void DataContractJsonSerializerSerializesEmptyAggregates()
{
using (var stream = new MemoryStream())
{
var serializer = new DataContractJsonSerializer(typeof(DataSourceResult));
var serializer = new DataContractJsonSerializer(typeof(DataSourceResult<Person>));

serializer.WriteObject(stream, new[] { "foo" }.AsQueryable<string>().ToDataSourceResult(1, 0, null, null));

Expand All @@ -34,7 +34,7 @@ public void DataContractJsonSerializerSerializesAggregates()
{
using (var stream = new MemoryStream())
{
var serializer = new DataContractJsonSerializer(typeof(DataSourceResult), new [] { typeof (Person) });
var serializer = new DataContractJsonSerializer(typeof(DataSourceResult<Person>), new [] { typeof (Person) });

var people = new[] { new Person { Age = 30 }, new Person { Age = 30 } };

Expand Down
3 changes: 2 additions & 1 deletion Kendo.DynamicLinq.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="2.6.3" targetFramework="net451" />
<package id="NUnit" version="3.9.0" targetFramework="net40" />
<package id="NUnit3TestAdapter" version="3.9.0" targetFramework="net40" />
</packages>
12 changes: 10 additions & 2 deletions Kendo.DynamicLinq.sln
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2010
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kendo.DynamicLinq", "Kendo.DynamicLinq\Kendo.DynamicLinq.csproj", "{2BD75D53-E0EA-4995-8B0F-60AD709945AC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kendo.DynamicLinq.Tests", "Kendo.DynamicLinq.Tests\Kendo.DynamicLinq.Tests.csproj", "{92FF629E-8872-4CCE-B558-F9FE437DDA86}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{5A216E56-452F-4090-B21A-B349857EEC19}"
ProjectSection(SolutionItems) = preProject
README.md = README.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -25,4 +30,7 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5B6DC219-AAEF-4710-ADE9-E302EFC75F55}
EndGlobalSection
EndGlobal
71 changes: 51 additions & 20 deletions Kendo.DynamicLinq/Aggregate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,24 @@ private static MethodInfo GetMethod(string methodName, MethodInfo methodTypes, i

private static Func<Type, Type[]> CountNullableFunc()
{
return (T) => new[]
{
typeof(IQueryable<>).MakeGenericType(T),
typeof(Expression<>).MakeGenericType(typeof(Func<,>).MakeGenericType(T, typeof(bool)))
};
}
//return (T) => new[]
// {
// typeof(IQueryable<>).MakeGenericType(T),
// typeof(Expression<>).MakeGenericType(typeof(Func<,>).MakeGenericType(T, typeof(bool)))
// };
return CountNullableDelegate;
}

private static Func<Type, Type[]> CountFunc()
private static Type[] CountNullableDelegate(Type t)
{
return new[]
{
typeof(IQueryable<>).MakeGenericType(t),
typeof(Expression<>).MakeGenericType(typeof(Func<,>).MakeGenericType(t, typeof(bool)))
};
}

private static Func<Type, Type[]> CountFunc()
{
return (T) => new[]
{
Expand All @@ -81,20 +91,41 @@ private static Func<Type, Type[]> CountFunc()

private static Func<Type, Type, Type[]> MinMaxFunc()
{
return (T, U) => new[]
{
typeof (IQueryable<>).MakeGenericType(T),
typeof (Expression<>).MakeGenericType(typeof (Func<,>).MakeGenericType(T, U))
};
}
//return (T, U) => new[]
// {
// typeof (IQueryable<>).MakeGenericType(T),
// typeof (Expression<>).MakeGenericType(typeof (Func<,>).MakeGenericType(T, U))
// };
return MinMaxDelegate;
}

private static Func<Type, Type[]> SumAvgFunc<U>()
private static Type[] MinMaxDelegate(Type a, Type b)
{
return new[]
{
typeof(IQueryable<>).MakeGenericType(a),
typeof(Expression<>).MakeGenericType(typeof(Func<,>).MakeGenericType(a, b))
};
}

private static Func<Type, Type[]> SumAvgFunc<U>()
{
return (T) => new[]
{
typeof (IQueryable<>).MakeGenericType(T),
typeof (Expression<>).MakeGenericType(typeof (Func<,>).MakeGenericType(T, typeof(U)))
};
//return (T) => new[]
// {
// typeof (IQueryable<>).MakeGenericType(T),
// typeof (Expression<>).MakeGenericType(typeof (Func<,>).MakeGenericType(T, typeof(U)))
// };
return SumAvgDelegate<U>;
}
}

private static Type[] SumAvgDelegate<TU>(Type t)
{
return new[]
{
typeof (IQueryable<>).MakeGenericType(t),
typeof (Expression<>).MakeGenericType(typeof (Func<,>).MakeGenericType(t, typeof(TU)))
};
}

}
}
2 changes: 1 addition & 1 deletion Kendo.DynamicLinq/DataSourceRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class DataSourceRequest
/// <summary>
/// Specifies the requested sort order.
/// </summary>
public IEnumerable<Sort> Sort { get; set; }
public List<Sort> Sort { get; set; }

/// <summary>
/// Specifies the requested filter.
Expand Down
4 changes: 2 additions & 2 deletions Kendo.DynamicLinq/DataSourceResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ namespace Kendo.DynamicLinq
/// Describes the result of Kendo DataSource read operation.
/// </summary>
[KnownType("GetKnownTypes")]
public class DataSourceResult
public class DataSourceResult<T>
{
/// <summary>
/// Represents a single page of processed data.
/// </summary>
public IEnumerable Data { get; set; }
public List<T> Data { get; set; }

/// <summary>
/// The total number of records available.
Expand Down
15 changes: 9 additions & 6 deletions Kendo.DynamicLinq/Filter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class Filter
/// Gets or sets the child filter expressions. Set to <c>null</c> if there are no child expressions.
/// </summary>
[DataMember(Name = "filters")]
public IEnumerable<Filter> Filters { get; set; }
public List<Filter> Filters { get; set; } // XmlSerializer needs List instead IEnumerable

/// <summary>
/// Mapping of Kendo DataSource filtering operators to Dynamic Linq
Expand All @@ -57,11 +57,11 @@ public class Filter
{"contains", "Contains"},
{"doesnotcontain", "Contains"}
};

/// <summary>
/// Get a flattened list of all child filter expressions.
/// </summary>
public IList<Filter> All()
public List<Filter> All()
{
var filters = new List<Filter>();

Expand All @@ -70,15 +70,18 @@ public IList<Filter> All()
return filters;
}

private void Collect(IList<Filter> filters)
private void Collect(List<Filter> filters)
{
if (Filters != null && Filters.Any())
{
foreach (Filter filter in Filters)
{
filters.Add(filter);

filter.Collect(filters);
if (filter.Filters?.Count > 0)
{
filter.Collect(filters);
}
}
}
else
Expand All @@ -91,7 +94,7 @@ private void Collect(IList<Filter> filters)
/// Converts the filter expression to a predicate suitable for Dynamic Linq e.g. "Field1 = @1 and Field2.Contains(@2)"
/// </summary>
/// <param name="filters">A list of flattened filters.</param>
public string ToExpression(IList<Filter> filters)
public string ToExpression(List<Filter> filters)
{
if (Filters != null && Filters.Any())
{
Expand Down
14 changes: 7 additions & 7 deletions Kendo.DynamicLinq/QueryableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ public static class QueryableExtensions
/// <param name="filter">Specifies the current filter.</param>
/// <param name="aggregates">Specifies the current aggregates.</param>
/// <returns>A DataSourceResult object populated from the processed IQueryable.</returns>
public static DataSourceResult ToDataSourceResult<T>(this IQueryable<T> queryable, int take, int skip, IEnumerable<Sort> sort, Filter filter, IEnumerable<Aggregator> aggregates)
public static DataSourceResult<T> ToDataSourceResult<T>(this IQueryable<T> queryable, int take, int skip, IEnumerable<Sort> sort, Filter filter, IEnumerable<Aggregator> aggregates)
{
// Filter the data first
queryable = Filter(queryable, filter);
// Filter the data first
queryable = Filter(queryable, filter);

// Calculate the total number of records (needed for paging)
var total = queryable.Count();
Expand All @@ -40,7 +40,7 @@ public static DataSourceResult ToDataSourceResult<T>(this IQueryable<T> queryabl
queryable = Page(queryable, take, skip);
}

return new DataSourceResult
return new DataSourceResult<T>
{
Data = queryable.ToList(),
Total = total,
Expand All @@ -58,7 +58,7 @@ public static DataSourceResult ToDataSourceResult<T>(this IQueryable<T> queryabl
/// <param name="sort">Specifies the current sort order.</param>
/// <param name="filter">Specifies the current filter.</param>
/// <returns>A DataSourceResult object populated from the processed IQueryable.</returns>
public static DataSourceResult ToDataSourceResult<T>(this IQueryable<T> queryable, int take, int skip, IEnumerable<Sort> sort, Filter filter)
public static DataSourceResult<T> ToDataSourceResult<T>(this IQueryable<T> queryable, int take, int skip, IEnumerable<Sort> sort, Filter filter)
{
return queryable.ToDataSourceResult(take, skip, sort, filter, null);
}
Expand All @@ -70,7 +70,7 @@ public static DataSourceResult ToDataSourceResult<T>(this IQueryable<T> queryabl
/// <param name="queryable">The IQueryable which should be processed.</param>
/// <param name="request">The DataSourceRequest object containing take, skip, order, and filter data.</param>
/// <returns>A DataSourceResult object populated from the processed IQueryable.</returns>
public static DataSourceResult ToDataSourceResult<T>(this IQueryable<T> queryable, DataSourceRequest request)
public static DataSourceResult<T> ToDataSourceResult<T>(this IQueryable<T> queryable, DataSourceRequest request)
{
return queryable.ToDataSourceResult(request.Take, request.Skip, request.Sort, request.Filter, null);
}
Expand All @@ -87,7 +87,7 @@ private static IQueryable<T> Filter<T>(IQueryable<T> queryable, Filter filter)

// Create a predicate expression e.g. Field1 = @0 And Field2 > @1
string predicate = filter.ToExpression(filters);

// Use the Where method of Dynamic Linq to filter the data
queryable = queryable.Where(predicate, values);
}
Expand Down
Binary file removed packages/NUnit.2.6.3/NUnit.2.6.3.nupkg
Binary file not shown.
27 changes: 0 additions & 27 deletions packages/NUnit.2.6.3/NUnit.2.6.3.nuspec

This file was deleted.

Binary file removed packages/NUnit.2.6.3/lib/nunit.framework.dll
Binary file not shown.
Loading