Skip to content

Commit

Permalink
Merge pull request #97 from AutoMapper/Microsoft.AspNetCore.OData.v8
Browse files Browse the repository at this point in the history
Supporting Microsoft.AspNetCore.OData v8.0.0-rc.
  • Loading branch information
BlaiseD authored Apr 10, 2021
2 parents de60983 + bb05cea commit a9a70bd
Show file tree
Hide file tree
Showing 32 changed files with 157 additions and 150 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
<MinVerTagPrefix>v</MinVerTagPrefix>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>TRACE;ASPNET</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DefineConstants>TRACE;ASPNET</DefineConstants>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\AutoMapper.AspNetCore.OData.EF6\QueryableExtensions.cs" Link="QueryableExtensions.cs" />
<Compile Include="..\AutoMapper.AspNetCore.OData.EFCore\AsyncSettings.cs" Link="AsyncSettings.cs" />
Expand Down
1 change: 0 additions & 1 deletion AutoMapper.AspNet.OData.EF6/ODataQueryOptionsExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Microsoft.AspNet.OData.Extensions;
using Microsoft.AspNet.OData.Query;
using System;

namespace AutoMapper.AspNet.OData
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.1;net461</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
<RootNamespace>AutoMapper.AspNet.OData</RootNamespace>
<PackageId>AutoMapper.AspNetCore.OData.EF6</PackageId>
<Description>Creates LINQ expressions from ODataQueryOptions and executes the query.</Description>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageReleaseNotes>Removing Task.Run form non-async calls. CancellationToken support. Restricting page size Server-side.</PackageReleaseNotes>
<PackageReleaseNotes>Supporting Microsoft.AspNetCore.OData v8.0.0-rc.</PackageReleaseNotes>
<PackageTags>linq expressions odata efcore</PackageTags>
<PackageIconUrl>https://s3.amazonaws.com/automapper/icon.png</PackageIconUrl>
<RepositoryUrl>https://github.com/AutoMapper/AutoMapper.Extensions.OData</RepositoryUrl>
Expand All @@ -17,6 +17,22 @@
<MinVerTagPrefix>v</MinVerTagPrefix>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|netstandard2.1|AnyCPU'">
<DefineConstants>TRACE;ASPNETCORE</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netstandard2.1|AnyCPU'">
<DefineConstants>TRACE;ASPNETCORE</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netcoreapp3.1|AnyCPU'">
<DefineConstants>TRACE;ASPNETCORE</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|netcoreapp3.1|AnyCPU'">
<DefineConstants>TRACE;ASPNETCORE</DefineConstants>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\AutoMapper.AspNetCore.OData.EFCore\AsyncSettings.cs" Link="AsyncSettings.cs" />
<Compile Include="..\AutoMapper.AspNetCore.OData.EFCore\Constants.cs" Link="Constants.cs" />
Expand Down Expand Up @@ -45,13 +61,17 @@
<PackageReference Include="AutoMapper.Extensions.ExpressionMapping" Version="[4.1.1,5.0.0)" />
<PackageReference Include="EntityFramework" Version="6.3.0" />
<PackageReference Include="LogicBuilder.Expressions.Utils" Version="[4.1.1,5.0.0)" />
<PackageReference Include="Microsoft.AspNetCore.OData" Version="7.4.1" />
<PackageReference Include="Microsoft.AspNetCore.OData" Version="8.0.0-rc" />
<PackageReference Include="MinVer" Version="2.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

<ItemGroup>
<Folder Include="Visitors\" />
<Folder Include="Properties\" />
Expand Down
6 changes: 5 additions & 1 deletion AutoMapper.AspNetCore.OData.EF6/QueryableExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
using AutoMapper.Extensions.ExpressionMapping;
using LogicBuilder.Expressions.Utils.Expansions;
#if ASPNET
using Microsoft.AspNet.OData.Query;
#endif
#if ASPNETCORE
using Microsoft.AspNetCore.OData.Query;
#endif
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>AutoMapper.AspNet.OData</RootNamespace>
<PackageId>AutoMapper.AspNetCore.OData.EFCore</PackageId>
<Description>Creates LINQ expressions from ODataQueryOptions and executes the query.</Description>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageReleaseNotes>Removing Task.Run form non-async calls. CancellationToken support. Restricting page size Server-side.</PackageReleaseNotes>
<PackageReleaseNotes>Supporting Microsoft.AspNetCore.OData v8.0.0-rc.</PackageReleaseNotes>
<PackageTags>linq expressions odata efcore</PackageTags>
<PackageIconUrl>https://s3.amazonaws.com/automapper/icon.png</PackageIconUrl>
<RepositoryUrl>https://github.com/AutoMapper/AutoMapper.Extensions.OData</RepositoryUrl>
Expand All @@ -17,16 +17,28 @@
<MinVerTagPrefix>v</MinVerTagPrefix>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DefineConstants>TRACE;ASPNETCORE</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>TRACE;ASPNETCORE</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AutoMapper.Extensions.ExpressionMapping" Version="[4.1.1,5.0.0)" />
<PackageReference Include="LogicBuilder.Expressions.Utils" Version="[4.1.1,5.0.0)" />
<PackageReference Include="Microsoft.AspNetCore.OData" Version="7.4.1" />
<PackageReference Include="Microsoft.AspNetCore.OData" Version="8.0.0-rc" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.0" />
<PackageReference Include="MinVer" Version="2.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
Expand Down
6 changes: 5 additions & 1 deletion AutoMapper.AspNetCore.OData.EFCore/LinqExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
using AutoMapper.AspNet.OData.Visitors;
using LogicBuilder.Expressions.Utils;
using LogicBuilder.Expressions.Utils.Expansions;
using Microsoft.AspNet.OData.Extensions;
#if ASPNET
using Microsoft.AspNet.OData.Query;
#endif
#if ASPNETCORE
using Microsoft.AspNetCore.OData.Query;
#endif
using Microsoft.OData.UriParser;
using System;
using System.Collections.Generic;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using Microsoft.AspNet.OData.Extensions;
using Microsoft.AspNet.OData.Query;
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.AspNetCore.OData.Extensions;
using Microsoft.AspNetCore.OData.Query;

namespace AutoMapper.AspNet.OData
{
Expand Down Expand Up @@ -43,7 +40,7 @@ public static void AddNextLinkOptionsResult(this ODataQueryOptions options, int
if (options.Request == null)
return;

options.Request.ODataFeature().NextLink = options.Request.GetNextPageLink(pageSize);
options.Request.ODataFeature().NextLink = options.Request.GetNextPageLink(pageSize, null, null);
}
}
}
8 changes: 7 additions & 1 deletion AutoMapper.AspNetCore.OData.EFCore/ODataSettings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
using Microsoft.AspNet.OData.Query;

#if ASPNET
using Microsoft.AspNet.OData.Query;
#endif
#if ASPNETCORE
using Microsoft.AspNetCore.OData.Query;
#endif

namespace AutoMapper.AspNet.OData
{
Expand Down
4 changes: 1 addition & 3 deletions AutoMapper.AspNetCore.OData.EFCore/QuerySettings.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Microsoft.AspNet.OData.Query;

namespace AutoMapper.AspNet.OData
namespace AutoMapper.AspNet.OData
{
/// <summary>
/// This class describes the settings to use during query composition.
Expand Down
2 changes: 1 addition & 1 deletion AutoMapper.AspNetCore.OData.EFCore/QueryableExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using AutoMapper.Extensions.ExpressionMapping;
using LogicBuilder.Expressions.Utils.Expansions;
using Microsoft.AspNet.OData.Query;
using Microsoft.AspNetCore.OData.Query;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Query;
using System;
Expand Down
3 changes: 0 additions & 3 deletions AutoMapper.OData.EF6.Tests/Data/DataClasses.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//Adapted from Microsoft.AspNet.OData.Test.Query.Expressions
using Microsoft.AspNet.OData.Query;
using Microsoft.OData.Edm;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -28,7 +27,6 @@ public class Product
public System.DateTime Birthday { get; set; }

public DateTimeOffset NonNullableDiscontinuedDate { get; set; }
[NotFilterable]
public DateTimeOffset NotFilterableDiscontinuedDate { get; set; }

public DateTimeOffset DiscontinuedOffset { get; set; }
Expand All @@ -53,7 +51,6 @@ public class Product

public int[] AlternateIDs { get; set; }
public Address[] AlternateAddresses { get; set; }
[NotFilterable]
public Address[] NotFilterableAlternateAddresses { get; set; }
}

Expand Down
16 changes: 8 additions & 8 deletions AutoMapper.OData.EF6.Tests/GetQuerySelectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
using AutoMapper.OData.EF6.Tests.Data;
using DAL.EF6;
using Domain.OData;
using Microsoft.AspNet.OData.Extensions;
using Microsoft.AspNet.OData.Query;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.OData;
using Microsoft.AspNetCore.OData.Query;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using System;
Expand Down Expand Up @@ -74,8 +74,8 @@ void Test(ICollection<OpsTenant> collection)
[Fact]
public async void BuildingSelectNameExpandBuilder_Builder_ShouldBeNull()
{
Test(Get<CoreBuilding, TBuilding>("/corebuilding?$top=5&$select=Name&$expand=Builder($select=Name)&$filter=name eq 'One L1'"));
Test(await GetAsync<CoreBuilding, TBuilding>("/corebuilding?$top=5&$select=Name&$expand=Builder($select=Name)&$filter=name eq 'One L1'"));
Test(Get<CoreBuilding, TBuilding>("/corebuilding?$top=5&$select=Name&$expand=Builder($select=Name)&$filter=Name eq 'One L1'"));
Test(await GetAsync<CoreBuilding, TBuilding>("/corebuilding?$top=5&$select=Name&$expand=Builder($select=Name)&$filter=Name eq 'One L1'"));

void Test(ICollection<CoreBuilding> collection)
{
Expand All @@ -89,8 +89,8 @@ void Test(ICollection<CoreBuilding> collection)
[Fact]
public async void BuildingExpandBuilderSelectNamefilterEqAndOrderBy()
{
Test(Get<CoreBuilding, TBuilding>("/corebuilding?$top=5&$expand=Builder($select=Name)&$filter=name eq 'One L1'"));
Test(await GetAsync<CoreBuilding, TBuilding>("/corebuilding?$top=5&$expand=Builder($select=Name)&$filter=name eq 'One L1'"));
Test(Get<CoreBuilding, TBuilding>("/corebuilding?$top=5&$expand=Builder($select=Name)&$filter=Name eq 'One L1'"));
Test(await GetAsync<CoreBuilding, TBuilding>("/corebuilding?$top=5&$expand=Builder($select=Name)&$filter=Name eq 'One L1'"));

void Test(ICollection<CoreBuilding> collection)
{
Expand All @@ -106,8 +106,8 @@ void Test(ICollection<CoreBuilding> collection)
[Fact]
public async void BuildingExpandBuilderSelectNameExpandCityFilterEqAndOrderBy_CityShouldBeNull_BuilderNameShouldeSam_BuilderIdShouldBeZero()
{
Test(Get<CoreBuilding, TBuilding>("/corebuilding?$top=5&$expand=Builder($select=Name;$expand=City)&$filter=name eq 'One L1'"));
Test(await GetAsync<CoreBuilding, TBuilding>("/corebuilding?$top=5&$expand=Builder($select=Name;$expand=City)&$filter=name eq 'One L1'"));
Test(Get<CoreBuilding, TBuilding>("/corebuilding?$top=5&$expand=Builder($select=Name;$expand=City)&$filter=Name eq 'One L1'"));
Test(await GetAsync<CoreBuilding, TBuilding>("/corebuilding?$top=5&$expand=Builder($select=Name;$expand=City)&$filter=Name eq 'One L1'"));

void Test(ICollection<CoreBuilding> collection)
{
Expand Down
17 changes: 9 additions & 8 deletions AutoMapper.OData.EF6.Tests/GetQueryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
using AutoMapper.OData.EF6.Tests.Model;
using DAL.EF6;
using Domain.OData;
using Microsoft.AspNet.OData.Extensions;
using Microsoft.AspNet.OData.Query;
using Microsoft.AspNetCore.OData.Extensions;
using Microsoft.AspNetCore.OData.Query;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -14,6 +14,7 @@
using System.Threading;
using System.Threading.Tasks;
using Xunit;
using Microsoft.AspNetCore.OData;

namespace AutoMapper.OData.EF6.Tests
{
Expand Down Expand Up @@ -205,7 +206,7 @@ public async void BuildingExpandBuilderTenantFilterEqAndOrderByWithParameter()
(
Get<CoreBuilding, TBuilding>
(
"/corebuilding?$top=1&$expand=Builder&$filter=name eq 'One L1'",
"/corebuilding?$top=1&$expand=Builder&$filter=Name eq 'One L1'",
null,
new QuerySettings
{
Expand All @@ -218,7 +219,7 @@ public async void BuildingExpandBuilderTenantFilterEqAndOrderByWithParameter()
(
await GetAsync<CoreBuilding, TBuilding>
(
"/corebuilding?$top=1&$expand=Builder&$filter=name eq 'One L1'",
"/corebuilding?$top=1&$expand=Builder&$filter=Name eq 'One L1'",
null,
new QuerySettings
{
Expand All @@ -241,8 +242,8 @@ void Test(ICollection<CoreBuilding> collection)
[Fact]
public async void BuildingExpandBuilderTenantFilterEqAndOrderBy()
{
Test(Get<CoreBuilding, TBuilding>("/corebuilding?$top=5&$expand=Builder,Tenant&$filter=name eq 'One L1'"));
Test(await GetAsync<CoreBuilding, TBuilding>("/corebuilding?$top=5&$expand=Builder,Tenant&$filter=name eq 'One L1'"));
Test(Get<CoreBuilding, TBuilding>("/corebuilding?$top=5&$expand=Builder,Tenant&$filter=Name eq 'One L1'"));
Test(await GetAsync<CoreBuilding, TBuilding>("/corebuilding?$top=5&$expand=Builder,Tenant&$filter=Name eq 'One L1'"));

void Test(ICollection<CoreBuilding> collection)
{
Expand All @@ -256,8 +257,8 @@ void Test(ICollection<CoreBuilding> collection)
[Fact]
public async void BuildingExpandBuilderSelectNameExpandTenantFilterEqAndOrderBy()
{
Test(Get<CoreBuilding, TBuilding>("/corebuilding?$top=5&$expand=Builder($select=Name),Tenant&$filter=name eq 'One L1'"));
Test(await GetAsync<CoreBuilding, TBuilding>("/corebuilding?$top=5&$expand=Builder($select=Name),Tenant&$filter=name eq 'One L1'"));
Test(Get<CoreBuilding, TBuilding>("/corebuilding?$top=5&$expand=Builder($select=Name),Tenant&$filter=Name eq 'One L1'"));
Test(await GetAsync<CoreBuilding, TBuilding>("/corebuilding?$top=5&$expand=Builder($select=Name),Tenant&$filter=Name eq 'One L1'"));

void Test(ICollection<CoreBuilding> collection)
{
Expand Down
19 changes: 8 additions & 11 deletions AutoMapper.OData.EF6.Tests/GetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
using AutoMapper.OData.EF6.Tests.Data;
using DAL.EF6;
using Domain.OData;
using Microsoft.AspNet.OData;
using Microsoft.AspNet.OData.Builder;
using Microsoft.AspNet.OData.Extensions;
using Microsoft.AspNet.OData.Query;
using Microsoft.AspNet.OData.Routing;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.OData;
using Microsoft.AspNetCore.OData.Extensions;
using Microsoft.AspNetCore.OData.Query;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OData.Edm;
using Microsoft.OData.ModelBuilder;
using Microsoft.OData.UriParser;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -148,8 +148,8 @@ void Test(ICollection<OpsTenant> collection)
[Fact]
public async void BuildingExpandBuilderTenantFilterEqAndOrderBy()
{
Test(Get<CoreBuilding, TBuilding>("/corebuilding?$top=5&$expand=Builder,Tenant&$filter=name eq 'One L1'"));
Test(await GetAsync<CoreBuilding, TBuilding>("/corebuilding?$top=5&$expand=Builder,Tenant&$filter=name eq 'One L1'"));
Test(Get<CoreBuilding, TBuilding>("/corebuilding?$top=5&$expand=Builder,Tenant&$filter=Name eq 'One L1'"));
Test(await GetAsync<CoreBuilding, TBuilding>("/corebuilding?$top=5&$expand=Builder,Tenant&$filter=Name eq 'One L1'"));

void Test(ICollection<CoreBuilding> collection)
{
Expand Down Expand Up @@ -530,16 +530,13 @@ public static class ODataHelpers
{
public static ODataQueryOptions<T> GetODataQueryOptions<T>(string queryString, IServiceProvider serviceProvider, IRouteBuilder routeBuilder) where T : class
{
ODataConventionModelBuilder builder = new ODataConventionModelBuilder(serviceProvider);
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();

builder.EntitySet<T>(typeof(T).Name);
builder.EnableLowerCamelCase();
IEdmModel model = builder.GetEdmModel();
IEdmEntitySet entitySet = model.EntityContainer.FindEntitySet(typeof(T).Name);
ODataPath path = new ODataPath(new Microsoft.OData.UriParser.EntitySetSegment(entitySet));

routeBuilder.EnableDependencyInjection();

return new ODataQueryOptions<T>
(
new ODataQueryContext(model, typeof(T), path),
Expand Down
Loading

0 comments on commit a9a70bd

Please sign in to comment.