Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit 709c355

Browse files
author
IharYakimush
authored
Merge pull request #16 from IharYakimush/aspnetcore
AspNetCore
2 parents b9cd097 + 9e83196 commit 709c355

20 files changed

+639
-55
lines changed

Community.Data.OData.Linq.sln

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Community.OData.Linq.Demo",
2020
EndProject
2121
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Community.OData.Linq.Json", "Community.OData.Linq.Json\Community.OData.Linq.Json.csproj", "{6C454F01-28D1-49B1-BE98-244E5DA2D095}"
2222
EndProject
23-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Community.OData.Linq.EF6Tests", "Community.OData.Linq.EF6Tests\Community.OData.Linq.EF6Tests.csproj", "{F034D1D8-D44A-4B0E-96C4-855F30B239BA}"
23+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Community.OData.Linq.EF6Tests", "Community.OData.Linq.EF6Tests\Community.OData.Linq.EF6Tests.csproj", "{F034D1D8-D44A-4B0E-96C4-855F30B239BA}"
24+
EndProject
25+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Community.OData.Linq.AspNetCore", "Community.OData.Linq.AspNetCore\Community.OData.Linq.AspNetCore.csproj", "{8F6BC2CA-5442-4A2E-A133-D62A93394ABE}"
26+
EndProject
27+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Community.OData.Linq.AspNetCore.IntegrationTests", "Community.OData.Linq.AspNetCore.IntegrationTests\Community.OData.Linq.AspNetCore.IntegrationTests.csproj", "{E879A557-82B2-4466-8A7C-590E3DFBFBF0}"
2428
EndProject
2529
Global
2630
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -59,6 +63,18 @@ Global
5963
{F034D1D8-D44A-4B0E-96C4-855F30B239BA}.Debug|Any CPU.Build.0 = Debug|Any CPU
6064
{F034D1D8-D44A-4B0E-96C4-855F30B239BA}.Release|Any CPU.ActiveCfg = Release|Any CPU
6165
{F034D1D8-D44A-4B0E-96C4-855F30B239BA}.Release|Any CPU.Build.0 = Release|Any CPU
66+
{8F6BC2CA-5442-4A2E-A133-D62A93394ABE}.CodeAnalysis|Any CPU.ActiveCfg = Debug|Any CPU
67+
{8F6BC2CA-5442-4A2E-A133-D62A93394ABE}.CodeAnalysis|Any CPU.Build.0 = Debug|Any CPU
68+
{8F6BC2CA-5442-4A2E-A133-D62A93394ABE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
69+
{8F6BC2CA-5442-4A2E-A133-D62A93394ABE}.Debug|Any CPU.Build.0 = Debug|Any CPU
70+
{8F6BC2CA-5442-4A2E-A133-D62A93394ABE}.Release|Any CPU.ActiveCfg = Release|Any CPU
71+
{8F6BC2CA-5442-4A2E-A133-D62A93394ABE}.Release|Any CPU.Build.0 = Release|Any CPU
72+
{E879A557-82B2-4466-8A7C-590E3DFBFBF0}.CodeAnalysis|Any CPU.ActiveCfg = Debug|Any CPU
73+
{E879A557-82B2-4466-8A7C-590E3DFBFBF0}.CodeAnalysis|Any CPU.Build.0 = Debug|Any CPU
74+
{E879A557-82B2-4466-8A7C-590E3DFBFBF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
75+
{E879A557-82B2-4466-8A7C-590E3DFBFBF0}.Debug|Any CPU.Build.0 = Debug|Any CPU
76+
{E879A557-82B2-4466-8A7C-590E3DFBFBF0}.Release|Any CPU.ActiveCfg = Release|Any CPU
77+
{E879A557-82B2-4466-8A7C-590E3DFBFBF0}.Release|Any CPU.Build.0 = Release|Any CPU
6278
EndGlobalSection
6379
GlobalSection(SolutionProperties) = preSolution
6480
HideSolutionNode = FALSE

Community.Data.OData.Linq.xTests/JsonTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,14 @@ public void SerializeSelectExpand()
2020

2121
Assert.DoesNotContain("ModelID", token.ToString(Formatting.None));
2222
}
23+
24+
[Fact]
25+
public void SerializeSelectExpand2()
26+
{
27+
JToken token = ClassWithCollection.CreateQuery().OData().SelectExpand("Name", "Link2($filter=Id eq 311;$select=Name)").ToJson();
28+
Assert.NotNull(token);
29+
30+
Assert.DoesNotContain("ModelID", token.ToString(Formatting.None));
31+
}
2332
}
2433
}

Community.Data.OData.Linq/Community.OData.Linq.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
<PackageProjectUrl>https://github.com/IharYakimush/comminity-data-odata-linq</PackageProjectUrl>
1212
<RepositoryType></RepositoryType>
1313
<PackageTags>odata filter linq netstandard</PackageTags>
14-
<PackageReleaseNotes>Added support for $top and $skip parameters</PackageReleaseNotes>
14+
<PackageReleaseNotes>Add support for ApplyQueryOptions and ApplyQueryOptionsWithoutSelectExpand methods.</PackageReleaseNotes>
1515
<Description>Use OData filter text query in linq expresson for any IQuerable without ASP.NET dependency. Support netstandard2.0</Description>
1616
<Company />
1717
<RepositoryUrl></RepositoryUrl>
18-
<Version>1.3.0</Version>
18+
<Version>1.4.0</Version>
1919
<NeutralLanguage>en</NeutralLanguage>
20-
<AssemblyVersion>1.3.0.0</AssemblyVersion>
21-
<FileVersion>1.3.0.0</FileVersion>
20+
<AssemblyVersion>1.4.0.0</AssemblyVersion>
21+
<FileVersion>1.4.0.0</FileVersion>
2222
</PropertyGroup>
2323

2424
<ItemGroup>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
namespace Community.OData.Linq
2+
{
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
6+
public interface IODataQueryOptions
7+
{
8+
/// <summary>
9+
/// Gets the raw $filter query value from the incoming request Uri if exists.
10+
/// </summary>
11+
IReadOnlyCollection<string> Filters { get; }
12+
13+
/// <summary>
14+
/// Gets the raw $orderby query value from the incoming request Uri if exists.
15+
/// </summary>
16+
string OrderBy { get; }
17+
18+
/// <summary>
19+
/// Gets the raw $top query value from the incoming request Uri if exists.
20+
/// </summary>
21+
string Top { get; }
22+
23+
/// <summary>
24+
/// Gets the raw $skip query value from the incoming request Uri if exists.
25+
/// </summary>
26+
string Skip { get; }
27+
28+
/// <summary>
29+
/// Gets the raw $select query value from the incoming request Uri if exists.
30+
/// </summary>
31+
string Select { get; }
32+
33+
/// <summary>
34+
/// Gets the raw $expand query value from the incoming request Uri if exists.
35+
/// </summary>
36+
string Expand { get; }
37+
}
38+
}

Community.Data.OData.Linq/OData/Query/ODataRawQueryOptions.cs

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,64 +3,91 @@
33

44
namespace Community.OData.Linq.OData.Query
55
{
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using System.Runtime.Serialization;
10+
611
/// <summary>
712
/// Represents the raw query values in the string format from the incoming request.
813
/// </summary>
9-
public class ODataRawQueryOptions
14+
[DataContract]
15+
[Serializable]
16+
public class ODataRawQueryOptions : IODataQueryOptions
1017
{
1118
/// <summary>
1219
/// Gets the raw $filter query value from the incoming request Uri if exists.
1320
/// </summary>
14-
public string Filter { get; internal set; }
21+
[IgnoreDataMember]
22+
IReadOnlyCollection<string> IODataQueryOptions.Filters
23+
{
24+
get
25+
{
26+
if (this.Filter == null)
27+
{
28+
return Enumerable.Empty<string>().ToArray();
29+
}
30+
31+
return Enumerable.Repeat(this.Filter, 1).ToArray();
32+
}
33+
}
34+
35+
[DataMember(Name = "$filter")]
36+
public virtual string Filter { get; set; }
1537

1638
/// <summary>
1739
/// Gets the raw $apply query value from the incoming request Uri if exists.
1840
/// </summary>
19-
public string Apply { get; internal set; }
41+
//public string Apply { get; set; }
2042

2143
/// <summary>
2244
/// Gets the raw $orderby query value from the incoming request Uri if exists.
2345
/// </summary>
24-
public string OrderBy { get; internal set; }
46+
[DataMember(Name = "$orderby")]
47+
public string OrderBy { get; set; }
2548

2649
/// <summary>
2750
/// Gets the raw $top query value from the incoming request Uri if exists.
2851
/// </summary>
29-
public string Top { get; internal set; }
52+
[DataMember(Name = "$top")]
53+
public string Top { get; set; }
3054

3155
/// <summary>
3256
/// Gets the raw $skip query value from the incoming request Uri if exists.
3357
/// </summary>
34-
public string Skip { get; internal set; }
58+
[DataMember(Name = "$skip")]
59+
public string Skip { get; set; }
3560

3661
/// <summary>
3762
/// Gets the raw $select query value from the incoming request Uri if exists.
3863
/// </summary>
39-
public string Select { get; internal set; }
64+
[DataMember(Name = "$select")]
65+
public string Select { get; set; }
4066

4167
/// <summary>
4268
/// Gets the raw $expand query value from the incoming request Uri if exists.
4369
/// </summary>
44-
public string Expand { get; internal set; }
70+
[DataMember(Name = "$expand")]
71+
public string Expand { get; set; }
4572

4673
/// <summary>
4774
/// Gets the raw $count query value from the incoming request Uri if exists.
4875
/// </summary>
49-
public string Count { get; internal set; }
76+
//public string Count { get; set; }
5077

5178
/// <summary>
5279
/// Gets the raw $format query value from the incoming request Uri if exists.
5380
/// </summary>
54-
public string Format { get; internal set; }
81+
//public string Format { get; set; }
5582

5683
/// <summary>
5784
/// Gets the raw $skiptoken query value from the incoming request Uri if exists.
5885
/// </summary>
59-
public string SkipToken { get; internal set; }
86+
//public string SkipToken { get; set; }
6087

6188
/// <summary>
6289
/// Gets the raw $deltatoken query value from the incoming request Uri if exists.
6390
/// </summary>
64-
public string DeltaToken { get; internal set; }
91+
//public string DeltaToken { get; set; }
6592
}
6693
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
namespace Community.OData.Linq
2+
{
3+
public class ODataParameters
4+
{
5+
/// <summary>
6+
/// Gets or sets the raw $apply query value from the incoming request Uri if exists.
7+
/// </summary>
8+
public string Apply { get; set; }
9+
10+
/// <summary>
11+
/// Gets or sets the raw $count query value from the incoming request Uri if exists.
12+
/// </summary>
13+
public string Count { get; set; }
14+
15+
/// <summary>
16+
/// Gets or sets the raw $deltatoken query value from the incoming request Uri if exists.
17+
/// </summary>
18+
public string DeltaToken { get; set; }
19+
20+
/// <summary>
21+
/// Gets or sets the raw $expand query value from the incoming request Uri if exists.
22+
/// </summary>
23+
public string Expand { get; set; }
24+
25+
/// <summary>
26+
/// Gets or sets the raw $filter query value from the incoming request Uri if exists.
27+
/// </summary>
28+
public string Filter { get; set; }
29+
30+
/// <summary>
31+
/// Gets or sets the raw $format query value from the incoming request Uri if exists.
32+
/// </summary>
33+
public string Format { get; set; }
34+
35+
/// <summary>
36+
/// Gets or sets the raw $orderby query value from the incoming request Uri if exists.
37+
/// </summary>
38+
public string OrderBy { get; set; }
39+
40+
/// <summary>
41+
/// Gets or sets the raw $select query value from the incoming request Uri if exists.
42+
/// </summary>
43+
public string Select { get; set; }
44+
45+
/// <summary>
46+
/// Gets or sets the raw $skip query value from the incoming request Uri if exists.
47+
/// </summary>
48+
public string Skip { get; set; }
49+
50+
/// <summary>
51+
/// Gets or sets the raw $skiptoken query value from the incoming request Uri if exists.
52+
/// </summary>
53+
public string SkipToken { get; set; }
54+
55+
/// <summary>
56+
/// Gets or sets the raw $top query value from the incoming request Uri if exists.
57+
/// </summary>
58+
public string Top { get; set; }
59+
}
60+
}

Community.Data.OData.Linq/OdataLinqExtensions.cs

Lines changed: 63 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -173,28 +173,70 @@ public static ODataQuery<T> TopSkip<T>(this ODataQuery<T> query, string topText
173173
return query;
174174
}
175175

176+
public static IQueryable<T> ApplyQueryOptionsWithoutSelectExpand<T>(
177+
this ODataQuery<T> query,
178+
IODataQueryOptions rawQueryOptions,
179+
string entitySetName = null)
180+
{
181+
return ApplyQueryOptionsInternal(query, rawQueryOptions, entitySetName);
182+
}
183+
184+
public static IEnumerable<ISelectExpandWrapper> ApplyQueryOptions<T>(
185+
this ODataQuery<T> query,
186+
IODataQueryOptions rawQueryOptions,
187+
string entitySetName = null)
188+
{
189+
return ApplyQueryOptionsInternal(query, rawQueryOptions, entitySetName).SelectExpand(
190+
rawQueryOptions.Select,
191+
rawQueryOptions.Expand,
192+
entitySetName);
193+
}
194+
195+
private static ODataQuery<T> ApplyQueryOptionsInternal<T>(ODataQuery<T> query, IODataQueryOptions rawQueryOptions, string entitySetName)
196+
{
197+
if (query == null) throw new ArgumentNullException(nameof(query));
198+
if (rawQueryOptions == null) throw new ArgumentNullException(nameof(rawQueryOptions));
199+
200+
if (rawQueryOptions.Filters != null)
201+
{
202+
foreach (string filter in rawQueryOptions.Filters)
203+
{
204+
query = query.Filter(filter, entitySetName);
205+
}
206+
}
207+
208+
if (rawQueryOptions.OrderBy != null)
209+
{
210+
query = query.OrderBy(rawQueryOptions.OrderBy, entitySetName);
211+
}
212+
213+
query = query.TopSkip(rawQueryOptions.Top, rawQueryOptions.Skip);
214+
215+
return query;
216+
}
217+
176218
/// <summary>
177-
/// The Filter.
178-
/// </summary>
179-
/// <param name="query">
180-
/// The OData aware query.
181-
/// </param>
182-
/// <param name="filterText">
183-
/// The $filter parameter text.
184-
/// </param>
185-
/// <param name="entitySetName">
186-
/// The entity set name.
187-
/// </param>
188-
/// <typeparam name="T">
189-
/// The query type param
190-
/// </typeparam>
191-
/// <returns>
192-
/// The <see cref="ODataQuery{T}"/> query with applied filter parameter.
193-
/// </returns>
194-
/// <exception cref="ArgumentNullException">
195-
/// Argument Null Exception
196-
/// </exception>
197-
public static ODataQuery<T> Filter<T>(this ODataQuery<T> query, string filterText, string entitySetName = null)
219+
/// The Filter.
220+
/// </summary>
221+
/// <param name="query">
222+
/// The OData aware query.
223+
/// </param>
224+
/// <param name="filterText">
225+
/// The $filter parameter text.
226+
/// </param>
227+
/// <param name="entitySetName">
228+
/// The entity set name.
229+
/// </param>
230+
/// <typeparam name="T">
231+
/// The query type param
232+
/// </typeparam>
233+
/// <returns>
234+
/// The <see cref="ODataQuery{T}"/> query with applied filter parameter.
235+
/// </returns>
236+
/// <exception cref="ArgumentNullException">
237+
/// Argument Null Exception
238+
/// </exception>
239+
public static ODataQuery<T> Filter<T>(this ODataQuery<T> query, string filterText, string entitySetName = null)
198240
{
199241
if (query == null) throw new ArgumentNullException(nameof(query));
200242
if (filterText == null) throw new ArgumentNullException(nameof(filterText));
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp2.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<Folder Include="wwwroot\" />
9+
</ItemGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.6" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<ProjectReference Include="..\Community.OData.Linq.AspNetCore\Community.OData.Linq.AspNetCore.csproj" />
17+
<ProjectReference Include="..\Community.OData.Linq.Json\Community.OData.Linq.Json.csproj" />
18+
</ItemGroup>
19+
20+
</Project>

0 commit comments

Comments
 (0)