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

Commit d4492cc

Browse files
Ihar YakimushIhar Yakimush
authored andcommitted
AspNetCore support
1 parent f4828e7 commit d4492cc

File tree

12 files changed

+134
-78
lines changed

12 files changed

+134
-78
lines changed

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<PackageProjectUrl>https://github.com/IharYakimush/comminity-data-odata-linq</PackageProjectUrl>
1212
<RepositoryType></RepositoryType>
1313
<PackageTags>odata filter linq netstandard</PackageTags>
14-
<PackageReleaseNotes>Add support for ApplyRawQueryOptionsWithSelectExpand and ApplyRawQueryOptionsWithoutSelectExpand</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>

Community.Data.OData.Linq/IODataRawQueryOptions.cs renamed to Community.Data.OData.Linq/IODataQueryOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.Collections.Generic;
44
using System.Linq;
55

6-
public interface IODataRawQueryOptions
6+
public interface IODataQueryOptions
77
{
88
/// <summary>
99
/// Gets the raw $filter query value from the incoming request Uri if exists.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ namespace Community.OData.Linq.OData.Query
1313
/// </summary>
1414
[DataContract]
1515
[Serializable]
16-
public class ODataRawQueryOptions : IODataRawQueryOptions
16+
public class ODataRawQueryOptions : IODataQueryOptions
1717
{
1818
/// <summary>
1919
/// Gets the raw $filter query value from the incoming request Uri if exists.
2020
/// </summary>
2121
[IgnoreDataMember]
22-
IReadOnlyCollection<string> IODataRawQueryOptions.Filters
22+
IReadOnlyCollection<string> IODataQueryOptions.Filters
2323
{
2424
get
2525
{

Community.Data.OData.Linq/OdataLinqExtensions.cs

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

176-
public static IQueryable<T> ApplyRawQueryOptionsWithoutSelectExpand<T>(
176+
public static IQueryable<T> ApplyQueryOptionsWithoutSelectExpand<T>(
177177
this ODataQuery<T> query,
178-
IODataRawQueryOptions rawQueryOptions,
178+
IODataQueryOptions rawQueryOptions,
179179
string entitySetName = null)
180180
{
181-
return ApplyRawQueryOptionsWithoutSelectExpandInternal(query, rawQueryOptions, entitySetName);
181+
return ApplyQueryOptionsInternal(query, rawQueryOptions, entitySetName);
182182
}
183183

184-
public static IEnumerable<ISelectExpandWrapper> ApplyRawQueryOptionsWithSelectExpand<T>(
184+
public static IEnumerable<ISelectExpandWrapper> ApplyQueryOptions<T>(
185185
this ODataQuery<T> query,
186-
IODataRawQueryOptions rawQueryOptions,
186+
IODataQueryOptions rawQueryOptions,
187187
string entitySetName = null)
188188
{
189-
return ApplyRawQueryOptionsWithoutSelectExpandInternal(query, rawQueryOptions, entitySetName).SelectExpand(
189+
return ApplyQueryOptionsInternal(query, rawQueryOptions, entitySetName).SelectExpand(
190190
rawQueryOptions.Select,
191191
rawQueryOptions.Expand,
192192
entitySetName);
193193
}
194194

195-
private static ODataQuery<T> ApplyRawQueryOptionsWithoutSelectExpandInternal<T>(ODataQuery<T> query, IODataRawQueryOptions rawQueryOptions, string entitySetName)
195+
private static ODataQuery<T> ApplyQueryOptionsInternal<T>(ODataQuery<T> query, IODataQueryOptions rawQueryOptions, string entitySetName)
196196
{
197197
if (query == null) throw new ArgumentNullException(nameof(query));
198198
if (rawQueryOptions == null) throw new ArgumentNullException(nameof(rawQueryOptions));
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
namespace Community.OData.Linq.AspNetCore.IntegrationTests.Controllers
1+
namespace Community.OData.Linq.AspNetCore.IntegrationTests
22
{
3-
using System;
4-
using System.Collections.Generic;
53
using System.Linq;
64

7-
using Microsoft.AspNetCore.Mvc;
5+
using Community.OData.Linq;
6+
using Community.OData.Linq.AspNetCore;
7+
88
using Community.OData.Linq.Json;
99

10+
using Microsoft.AspNetCore.Mvc;
1011
using Microsoft.OData;
1112

1213
using Newtonsoft.Json.Linq;
@@ -15,52 +16,51 @@ public class ValuesController : Controller
1516
{
1617
[Route("/v1")]
1718
[HttpGet]
18-
public IActionResult Get1(ODataQueryOptions queryOptions)
19+
public IActionResult Get(ODataQueryOptions queryOptions)
1920
{
20-
if (queryOptions == null && !this.ModelState.IsValid )
21+
if (queryOptions == null && !this.ModelState.IsValid)
2122
{
2223
return this.BadRequest(this.ModelState);
2324
}
2425

25-
IQueryable<SampleData> data = Enumerable.Range(1, 10)
26-
.Select(i => new SampleData { Id = i, Name = $"n{i}" })
26+
IQueryable<Entity> data = Enumerable.Range(1, 10)
27+
.Select(i => new Entity { Id = i, Name = $"n{i}" })
2728
.ToArray()
2829
.AsQueryable();
29-
3030
try
3131
{
32-
SampleData[] result = data.OData().ApplyRawQueryOptionsWithoutSelectExpand(queryOptions).ToArray();
32+
JToken result = data.OData().ApplyQueryOptions(queryOptions).ToJson();
3333
return this.Ok(result);
3434
}
3535
catch (ODataException e)
3636
{
37-
this.ModelState.TryAddModelError("odata", e.Message);
38-
return this.BadRequest(this.ModelState);
37+
return this.BadRequest(e.Message);
3938
}
4039
}
4140

4241
[Route("/v2")]
4342
[HttpGet]
44-
public IActionResult Get2(ODataQueryOptions queryOptions)
43+
public IActionResult GetWithoutSelectExpand(ODataQueryOptions queryOptions)
4544
{
4645
if (queryOptions == null && !this.ModelState.IsValid)
4746
{
4847
return this.BadRequest(this.ModelState);
4948
}
5049

51-
IQueryable<SampleData> data = Enumerable.Range(1, 10)
52-
.Select(i => new SampleData { Id = i, Name = $"n{i}" })
50+
IQueryable<Entity> data = Enumerable.Range(1, 10)
51+
.Select(i => new Entity { Id = i, Name = $"n{i}" })
5352
.ToArray()
5453
.AsQueryable();
54+
5555
try
5656
{
57-
JToken result = data.OData().ApplyRawQueryOptionsWithSelectExpandJsonToken(queryOptions);
57+
Entity[] result = data.OData().ApplyQueryOptionsWithoutSelectExpand(queryOptions).ToArray();
5858
return this.Ok(result);
5959
}
6060
catch (ODataException e)
6161
{
6262
return this.BadRequest(e.Message);
6363
}
64-
}
64+
}
6565
}
6666
}

Community.OData.Linq.AspNetCore.IntegrationTests/SampleData.cs renamed to Community.OData.Linq.AspNetCore.IntegrationTests/Entity.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace Community.OData.Linq.AspNetCore.IntegrationTests
22
{
3-
public class SampleData
3+
public class Entity
44
{
55
public int Id { get; set; }
66

Community.OData.Linq.AspNetCore/Community.OData.Linq.AspNetCore.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<PackageLicenseUrl>https://github.com/IharYakimush/comminity-data-odata-linq/blob/master/LICENSE</PackageLicenseUrl>
88
<PackageProjectUrl>https://github.com/IharYakimush/comminity-data-odata-linq</PackageProjectUrl>
99
<PackageTags>odata linq aspnetcore</PackageTags>
10-
<Description>ASP.NET Core use OData query parameters in linq expressons</Description>
10+
<Description>OData linq for ASP.NET Core 2.0</Description>
1111
<PackageReleaseNotes>IModelBinder and IModelBinderProvider for ODataQueryOptions.</PackageReleaseNotes>
1212
</PropertyGroup>
1313

Community.OData.Linq.AspNetCore/ODataQueryOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
[DataContract]
1313
[Serializable]
1414
[ModelBinder(BinderType = typeof(ODataQueryOptionsModelBinder))]
15-
public class ODataQueryOptions : ODataRawQueryOptions, IODataRawQueryOptions
15+
public class ODataQueryOptions : ODataRawQueryOptions, IODataQueryOptions
1616
{
1717
public IReadOnlyCollection<string> Filters { get; set; }
1818

Community.OData.Linq.Json/Community.OData.Linq.Json.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<PackageProjectUrl>https://github.com/IharYakimush/comminity-data-odata-linq</PackageProjectUrl>
1212
<RepositoryType></RepositoryType>
1313
<PackageTags>odata filter linq json</PackageTags>
14-
<PackageReleaseNotes>Add support for ODataRawQueryOptions in Select methods</PackageReleaseNotes>
14+
<PackageReleaseNotes></PackageReleaseNotes>
1515
<Description>Json serialization for SelectExpand result</Description>
1616
<Company />
1717
<RepositoryUrl></RepositoryUrl>

0 commit comments

Comments
 (0)