diff --git a/AutoMapper.AspNet.OData.EF6/AutoMapper.AspNet.OData.EF6.csproj b/AutoMapper.AspNet.OData.EF6/AutoMapper.AspNet.OData.EF6.csproj index 80519e9..1db9d24 100644 --- a/AutoMapper.AspNet.OData.EF6/AutoMapper.AspNet.OData.EF6.csproj +++ b/AutoMapper.AspNet.OData.EF6/AutoMapper.AspNet.OData.EF6.csproj @@ -17,6 +17,14 @@ v + + TRACE;ASPNET + + + + TRACE;ASPNET + + diff --git a/AutoMapper.AspNet.OData.EF6/ODataQueryOptionsExtensions.cs b/AutoMapper.AspNet.OData.EF6/ODataQueryOptionsExtensions.cs index 6928702..1124335 100644 --- a/AutoMapper.AspNet.OData.EF6/ODataQueryOptionsExtensions.cs +++ b/AutoMapper.AspNet.OData.EF6/ODataQueryOptionsExtensions.cs @@ -1,6 +1,5 @@ using Microsoft.AspNet.OData.Extensions; using Microsoft.AspNet.OData.Query; -using System; namespace AutoMapper.AspNet.OData { diff --git a/AutoMapper.AspNetCore.OData.EF6/AutoMapper.AspNetCore.OData.EF6.csproj b/AutoMapper.AspNetCore.OData.EF6/AutoMapper.AspNetCore.OData.EF6.csproj index fbaf10d..607a6d2 100644 --- a/AutoMapper.AspNetCore.OData.EF6/AutoMapper.AspNetCore.OData.EF6.csproj +++ b/AutoMapper.AspNetCore.OData.EF6/AutoMapper.AspNetCore.OData.EF6.csproj @@ -1,12 +1,12 @@  - netstandard2.1;net461 + netcoreapp3.1 AutoMapper.AspNet.OData AutoMapper.AspNetCore.OData.EF6 Creates LINQ expressions from ODataQueryOptions and executes the query. false - Removing Task.Run form non-async calls. CancellationToken support. Restricting page size Server-side. + Supporting Microsoft.AspNetCore.OData v8.0.0-rc. linq expressions odata efcore https://s3.amazonaws.com/automapper/icon.png https://github.com/AutoMapper/AutoMapper.Extensions.OData @@ -17,6 +17,22 @@ v + + TRACE;ASPNETCORE + + + + TRACE;ASPNETCORE + + + + TRACE;ASPNETCORE + + + + TRACE;ASPNETCORE + + @@ -45,13 +61,17 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive + + + + diff --git a/AutoMapper.AspNetCore.OData.EF6/QueryableExtensions.cs b/AutoMapper.AspNetCore.OData.EF6/QueryableExtensions.cs index bc1a8ca..2c0a990 100644 --- a/AutoMapper.AspNetCore.OData.EF6/QueryableExtensions.cs +++ b/AutoMapper.AspNetCore.OData.EF6/QueryableExtensions.cs @@ -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; diff --git a/AutoMapper.AspNetCore.OData.EFCore/AutoMapper.AspNetCore.OData.EFCore.csproj b/AutoMapper.AspNetCore.OData.EFCore/AutoMapper.AspNetCore.OData.EFCore.csproj index 43e0d1a..d1ec41d 100644 --- a/AutoMapper.AspNetCore.OData.EFCore/AutoMapper.AspNetCore.OData.EFCore.csproj +++ b/AutoMapper.AspNetCore.OData.EFCore/AutoMapper.AspNetCore.OData.EFCore.csproj @@ -1,12 +1,12 @@  - netstandard2.0 + netcoreapp3.1 AutoMapper.AspNet.OData AutoMapper.AspNetCore.OData.EFCore Creates LINQ expressions from ODataQueryOptions and executes the query. false - Removing Task.Run form non-async calls. CancellationToken support. Restricting page size Server-side. + Supporting Microsoft.AspNetCore.OData v8.0.0-rc. linq expressions odata efcore https://s3.amazonaws.com/automapper/icon.png https://github.com/AutoMapper/AutoMapper.Extensions.OData @@ -17,16 +17,28 @@ v + + TRACE;ASPNETCORE + + + + TRACE;ASPNETCORE + + - + all runtime; build; native; contentfiles; analyzers; buildtransitive + + + + diff --git a/AutoMapper.AspNetCore.OData.EFCore/LinqExtensions.cs b/AutoMapper.AspNetCore.OData.EFCore/LinqExtensions.cs index 310a002..591fbcb 100644 --- a/AutoMapper.AspNetCore.OData.EFCore/LinqExtensions.cs +++ b/AutoMapper.AspNetCore.OData.EFCore/LinqExtensions.cs @@ -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; diff --git a/AutoMapper.AspNetCore.OData.EFCore/ODataQueryOptionsExtensions.cs b/AutoMapper.AspNetCore.OData.EFCore/ODataQueryOptionsExtensions.cs index cb37671..b6f7f0f 100644 --- a/AutoMapper.AspNetCore.OData.EFCore/ODataQueryOptionsExtensions.cs +++ b/AutoMapper.AspNetCore.OData.EFCore/ODataQueryOptionsExtensions.cs @@ -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 { @@ -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); } } } diff --git a/AutoMapper.AspNetCore.OData.EFCore/ODataSettings.cs b/AutoMapper.AspNetCore.OData.EFCore/ODataSettings.cs index d0be3ee..843e353 100644 --- a/AutoMapper.AspNetCore.OData.EFCore/ODataSettings.cs +++ b/AutoMapper.AspNetCore.OData.EFCore/ODataSettings.cs @@ -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 { diff --git a/AutoMapper.AspNetCore.OData.EFCore/QuerySettings.cs b/AutoMapper.AspNetCore.OData.EFCore/QuerySettings.cs index 494e532..52335ba 100644 --- a/AutoMapper.AspNetCore.OData.EFCore/QuerySettings.cs +++ b/AutoMapper.AspNetCore.OData.EFCore/QuerySettings.cs @@ -1,6 +1,4 @@ -using Microsoft.AspNet.OData.Query; - -namespace AutoMapper.AspNet.OData +namespace AutoMapper.AspNet.OData { /// /// This class describes the settings to use during query composition. diff --git a/AutoMapper.AspNetCore.OData.EFCore/QueryableExtensions.cs b/AutoMapper.AspNetCore.OData.EFCore/QueryableExtensions.cs index 6f567d2..6552bd4 100644 --- a/AutoMapper.AspNetCore.OData.EFCore/QueryableExtensions.cs +++ b/AutoMapper.AspNetCore.OData.EFCore/QueryableExtensions.cs @@ -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; diff --git a/AutoMapper.OData.EF6.Tests/Data/DataClasses.cs b/AutoMapper.OData.EF6.Tests/Data/DataClasses.cs index d8e8e88..a093e73 100644 --- a/AutoMapper.OData.EF6.Tests/Data/DataClasses.cs +++ b/AutoMapper.OData.EF6.Tests/Data/DataClasses.cs @@ -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; @@ -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; } @@ -53,7 +51,6 @@ public class Product public int[] AlternateIDs { get; set; } public Address[] AlternateAddresses { get; set; } - [NotFilterable] public Address[] NotFilterableAlternateAddresses { get; set; } } diff --git a/AutoMapper.OData.EF6.Tests/GetQuerySelectTests.cs b/AutoMapper.OData.EF6.Tests/GetQuerySelectTests.cs index e5303c0..152aef5 100644 --- a/AutoMapper.OData.EF6.Tests/GetQuerySelectTests.cs +++ b/AutoMapper.OData.EF6.Tests/GetQuerySelectTests.cs @@ -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; @@ -74,8 +74,8 @@ void Test(ICollection collection) [Fact] public async void BuildingSelectNameExpandBuilder_Builder_ShouldBeNull() { - Test(Get("/corebuilding?$top=5&$select=Name&$expand=Builder($select=Name)&$filter=name eq 'One L1'")); - Test(await GetAsync("/corebuilding?$top=5&$select=Name&$expand=Builder($select=Name)&$filter=name eq 'One L1'")); + Test(Get("/corebuilding?$top=5&$select=Name&$expand=Builder($select=Name)&$filter=Name eq 'One L1'")); + Test(await GetAsync("/corebuilding?$top=5&$select=Name&$expand=Builder($select=Name)&$filter=Name eq 'One L1'")); void Test(ICollection collection) { @@ -89,8 +89,8 @@ void Test(ICollection collection) [Fact] public async void BuildingExpandBuilderSelectNamefilterEqAndOrderBy() { - Test(Get("/corebuilding?$top=5&$expand=Builder($select=Name)&$filter=name eq 'One L1'")); - Test(await GetAsync("/corebuilding?$top=5&$expand=Builder($select=Name)&$filter=name eq 'One L1'")); + Test(Get("/corebuilding?$top=5&$expand=Builder($select=Name)&$filter=Name eq 'One L1'")); + Test(await GetAsync("/corebuilding?$top=5&$expand=Builder($select=Name)&$filter=Name eq 'One L1'")); void Test(ICollection collection) { @@ -106,8 +106,8 @@ void Test(ICollection collection) [Fact] public async void BuildingExpandBuilderSelectNameExpandCityFilterEqAndOrderBy_CityShouldBeNull_BuilderNameShouldeSam_BuilderIdShouldBeZero() { - Test(Get("/corebuilding?$top=5&$expand=Builder($select=Name;$expand=City)&$filter=name eq 'One L1'")); - Test(await GetAsync("/corebuilding?$top=5&$expand=Builder($select=Name;$expand=City)&$filter=name eq 'One L1'")); + Test(Get("/corebuilding?$top=5&$expand=Builder($select=Name;$expand=City)&$filter=Name eq 'One L1'")); + Test(await GetAsync("/corebuilding?$top=5&$expand=Builder($select=Name;$expand=City)&$filter=Name eq 'One L1'")); void Test(ICollection collection) { diff --git a/AutoMapper.OData.EF6.Tests/GetQueryTests.cs b/AutoMapper.OData.EF6.Tests/GetQueryTests.cs index 6488a4d..1ecdc9b 100644 --- a/AutoMapper.OData.EF6.Tests/GetQueryTests.cs +++ b/AutoMapper.OData.EF6.Tests/GetQueryTests.cs @@ -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; @@ -14,6 +14,7 @@ using System.Threading; using System.Threading.Tasks; using Xunit; +using Microsoft.AspNetCore.OData; namespace AutoMapper.OData.EF6.Tests { @@ -205,7 +206,7 @@ public async void BuildingExpandBuilderTenantFilterEqAndOrderByWithParameter() ( Get ( - "/corebuilding?$top=1&$expand=Builder&$filter=name eq 'One L1'", + "/corebuilding?$top=1&$expand=Builder&$filter=Name eq 'One L1'", null, new QuerySettings { @@ -218,7 +219,7 @@ public async void BuildingExpandBuilderTenantFilterEqAndOrderByWithParameter() ( await GetAsync ( - "/corebuilding?$top=1&$expand=Builder&$filter=name eq 'One L1'", + "/corebuilding?$top=1&$expand=Builder&$filter=Name eq 'One L1'", null, new QuerySettings { @@ -241,8 +242,8 @@ void Test(ICollection collection) [Fact] public async void BuildingExpandBuilderTenantFilterEqAndOrderBy() { - Test(Get("/corebuilding?$top=5&$expand=Builder,Tenant&$filter=name eq 'One L1'")); - Test(await GetAsync("/corebuilding?$top=5&$expand=Builder,Tenant&$filter=name eq 'One L1'")); + Test(Get("/corebuilding?$top=5&$expand=Builder,Tenant&$filter=Name eq 'One L1'")); + Test(await GetAsync("/corebuilding?$top=5&$expand=Builder,Tenant&$filter=Name eq 'One L1'")); void Test(ICollection collection) { @@ -256,8 +257,8 @@ void Test(ICollection collection) [Fact] public async void BuildingExpandBuilderSelectNameExpandTenantFilterEqAndOrderBy() { - Test(Get("/corebuilding?$top=5&$expand=Builder($select=Name),Tenant&$filter=name eq 'One L1'")); - Test(await GetAsync("/corebuilding?$top=5&$expand=Builder($select=Name),Tenant&$filter=name eq 'One L1'")); + Test(Get("/corebuilding?$top=5&$expand=Builder($select=Name),Tenant&$filter=Name eq 'One L1'")); + Test(await GetAsync("/corebuilding?$top=5&$expand=Builder($select=Name),Tenant&$filter=Name eq 'One L1'")); void Test(ICollection collection) { diff --git a/AutoMapper.OData.EF6.Tests/GetTests.cs b/AutoMapper.OData.EF6.Tests/GetTests.cs index 767f0d3..f358a04 100644 --- a/AutoMapper.OData.EF6.Tests/GetTests.cs +++ b/AutoMapper.OData.EF6.Tests/GetTests.cs @@ -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; @@ -148,8 +148,8 @@ void Test(ICollection collection) [Fact] public async void BuildingExpandBuilderTenantFilterEqAndOrderBy() { - Test(Get("/corebuilding?$top=5&$expand=Builder,Tenant&$filter=name eq 'One L1'")); - Test(await GetAsync("/corebuilding?$top=5&$expand=Builder,Tenant&$filter=name eq 'One L1'")); + Test(Get("/corebuilding?$top=5&$expand=Builder,Tenant&$filter=Name eq 'One L1'")); + Test(await GetAsync("/corebuilding?$top=5&$expand=Builder,Tenant&$filter=Name eq 'One L1'")); void Test(ICollection collection) { @@ -530,16 +530,13 @@ public static class ODataHelpers { public static ODataQueryOptions GetODataQueryOptions(string queryString, IServiceProvider serviceProvider, IRouteBuilder routeBuilder) where T : class { - ODataConventionModelBuilder builder = new ODataConventionModelBuilder(serviceProvider); + ODataConventionModelBuilder builder = new ODataConventionModelBuilder(); builder.EntitySet(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 ( new ODataQueryContext(model, typeof(T), path), diff --git a/AutoMapper.OData.EF6.Tests/Model/ModelClasses.cs b/AutoMapper.OData.EF6.Tests/Model/ModelClasses.cs index 4f4898f..94d29f8 100644 --- a/AutoMapper.OData.EF6.Tests/Model/ModelClasses.cs +++ b/AutoMapper.OData.EF6.Tests/Model/ModelClasses.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNet.OData.Query; + using Microsoft.OData.Edm; using System; using System.Collections.Generic; @@ -30,7 +30,6 @@ public class ProductModel public System.DateTime Birthday { get; set; } public DateTimeOffset NonNullableDiscontinuedDate { get; set; } - [NotFilterable] public DateTimeOffset NotFilterableDiscontinuedDate { get; set; } public DateTimeOffset DiscontinuedOffset { get; set; } @@ -55,7 +54,6 @@ public class ProductModel public int[] AlternateIDs { get; set; } public AddressModel[] AlternateAddresses { get; set; } - [NotFilterable] public AddressModel[] NotFilterableAlternateAddresses { get; set; } } diff --git a/AutoMapper.OData.EFCore.Tests/AutoMapper.OData.EFCore.Tests.csproj b/AutoMapper.OData.EFCore.Tests/AutoMapper.OData.EFCore.Tests.csproj index 9c370f0..fe5ee81 100644 --- a/AutoMapper.OData.EFCore.Tests/AutoMapper.OData.EFCore.Tests.csproj +++ b/AutoMapper.OData.EFCore.Tests/AutoMapper.OData.EFCore.Tests.csproj @@ -7,7 +7,6 @@ - diff --git a/AutoMapper.OData.EFCore.Tests/Data/DataClasses.cs b/AutoMapper.OData.EFCore.Tests/Data/DataClasses.cs index f9ca3ae..80fb571 100644 --- a/AutoMapper.OData.EFCore.Tests/Data/DataClasses.cs +++ b/AutoMapper.OData.EFCore.Tests/Data/DataClasses.cs @@ -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; @@ -29,7 +28,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; } @@ -54,7 +52,6 @@ public class Product public int[] AlternateIDs { get; set; } public Address[] AlternateAddresses { get; set; } - [NotFilterable] public Address[] NotFilterableAlternateAddresses { get; set; } } diff --git a/AutoMapper.OData.EFCore.Tests/GetQuerySelectTests.cs b/AutoMapper.OData.EFCore.Tests/GetQuerySelectTests.cs index 8e01200..06314dc 100644 --- a/AutoMapper.OData.EFCore.Tests/GetQuerySelectTests.cs +++ b/AutoMapper.OData.EFCore.Tests/GetQuerySelectTests.cs @@ -2,9 +2,9 @@ using AutoMapper.OData.EFCore.Tests.Data; using DAL.EFCore; 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.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; @@ -87,8 +87,8 @@ void Test(ICollection collection) [Fact] public async void BuildingSelectNameExpandBuilder_Builder_ShouldBeNull() { - Test(Get("/corebuilding?$top=5&$select=Name&$expand=Builder($select=Name)&$filter=name eq 'One L1'")); - Test(await GetAsync("/corebuilding?$top=5&$select=Name&$expand=Builder($select=Name)&$filter=name eq 'One L1'")); + Test(Get("/corebuilding?$top=5&$select=Name&$expand=Builder($select=Name)&$filter=Name eq 'One L1'")); + Test(await GetAsync("/corebuilding?$top=5&$select=Name&$expand=Builder($select=Name)&$filter=Name eq 'One L1'")); void Test(ICollection collection) { @@ -102,8 +102,8 @@ void Test(ICollection collection) [Fact] public async void BuildingExpandBuilderSelectNamefilterEqAndOrderBy() { - Test(Get("/corebuilding?$top=5&$expand=Builder($select=Name)&$filter=name eq 'One L1'")); - Test(await GetAsync("/corebuilding?$top=5&$expand=Builder($select=Name)&$filter=name eq 'One L1'")); + Test(Get("/corebuilding?$top=5&$expand=Builder($select=Name)&$filter=Name eq 'One L1'")); + Test(await GetAsync("/corebuilding?$top=5&$expand=Builder($select=Name)&$filter=Name eq 'One L1'")); void Test(ICollection collection) { @@ -119,8 +119,8 @@ void Test(ICollection collection) [Fact] public async void BuildingExpandBuilderSelectNameExpandCityFilterEqAndOrderBy_CityShouldBeNull_BuilderNameShouldeSam_BuilderIdShouldBeZero() { - Test(Get("/corebuilding?$top=5&$expand=Builder($select=Name;$expand=City)&$filter=name eq 'One L1'")); - Test(await GetAsync("/corebuilding?$top=5&$expand=Builder($select=Name;$expand=City)&$filter=name eq 'One L1'")); + Test(Get("/corebuilding?$top=5&$expand=Builder($select=Name;$expand=City)&$filter=Name eq 'One L1'")); + Test(await GetAsync("/corebuilding?$top=5&$expand=Builder($select=Name;$expand=City)&$filter=Name eq 'One L1'")); void Test(ICollection collection) { diff --git a/AutoMapper.OData.EFCore.Tests/GetQueryTests.cs b/AutoMapper.OData.EFCore.Tests/GetQueryTests.cs index b238e47..67253ac 100644 --- a/AutoMapper.OData.EFCore.Tests/GetQueryTests.cs +++ b/AutoMapper.OData.EFCore.Tests/GetQueryTests.cs @@ -3,9 +3,10 @@ using AutoMapper.OData.EFCore.Tests.Model; using DAL.EFCore; 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.Extensions; +using Microsoft.AspNetCore.OData.Query; using Microsoft.AspNetCore.Routing; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; @@ -218,7 +219,7 @@ public async void BuildingExpandBuilderTenantFilterEqAndOrderByWithParameter() ( Get ( - "/corebuilding?$top=1&$expand=Builder&$filter=name eq 'One L1'", + "/corebuilding?$top=1&$expand=Builder&$filter=Name eq 'One L1'", null, new QuerySettings { @@ -231,7 +232,7 @@ public async void BuildingExpandBuilderTenantFilterEqAndOrderByWithParameter() ( await GetAsync ( - "/corebuilding?$top=1&$expand=Builder&$filter=name eq 'One L1'", + "/corebuilding?$top=1&$expand=Builder&$filter=Name eq 'One L1'", null, new QuerySettings { @@ -254,8 +255,8 @@ void Test(ICollection collection) [Fact] public async void BuildingExpandBuilderTenantFilterEqAndOrderBy() { - Test(Get("/corebuilding?$top=5&$expand=Builder,Tenant&$filter=name eq 'One L1'")); - Test(await GetAsync("/corebuilding?$top=5&$expand=Builder,Tenant&$filter=name eq 'One L1'")); + Test(Get("/corebuilding?$top=5&$expand=Builder,Tenant&$filter=Name eq 'One L1'")); + Test(await GetAsync("/corebuilding?$top=5&$expand=Builder,Tenant&$filter=Name eq 'One L1'")); void Test(ICollection collection) { @@ -269,8 +270,8 @@ void Test(ICollection collection) [Fact] public async void BuildingExpandBuilderSelectNameExpandTenantFilterEqAndOrderBy() { - Test(Get("/corebuilding?$top=5&$expand=Builder($select=Name),Tenant&$filter=name eq 'One L1'")); - Test(await GetAsync("/corebuilding?$top=5&$expand=Builder($select=Name),Tenant&$filter=name eq 'One L1'")); + Test(Get("/corebuilding?$top=5&$expand=Builder($select=Name),Tenant&$filter=Name eq 'One L1'")); + Test(await GetAsync("/corebuilding?$top=5&$expand=Builder($select=Name),Tenant&$filter=Name eq 'One L1'")); void Test(ICollection collection) { diff --git a/AutoMapper.OData.EFCore.Tests/GetTests.cs b/AutoMapper.OData.EFCore.Tests/GetTests.cs index e1f9941..536bde8 100644 --- a/AutoMapper.OData.EFCore.Tests/GetTests.cs +++ b/AutoMapper.OData.EFCore.Tests/GetTests.cs @@ -2,17 +2,17 @@ using AutoMapper.OData.EFCore.Tests.Data; using DAL.EFCore; 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.EntityFrameworkCore; 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; @@ -161,8 +161,8 @@ void Test(ICollection collection) [Fact] public async void BuildingExpandBuilderTenantFilterEqAndOrderBy() { - Test(Get("/corebuilding?$top=5&$expand=Builder,Tenant&$filter=name eq 'One L1'")); - Test(await GetAsync("/corebuilding?$top=5&$expand=Builder,Tenant&$filter=name eq 'One L1'")); + Test(Get("/corebuilding?$top=5&$expand=Builder,Tenant&$filter=Name eq 'One L1'")); + Test(await GetAsync("/corebuilding?$top=5&$expand=Builder,Tenant&$filter=Name eq 'One L1'")); void Test(ICollection collection) { @@ -543,15 +543,13 @@ public static class ODataHelpers { public static ODataQueryOptions GetODataQueryOptions(string queryString, IServiceProvider serviceProvider, IRouteBuilder routeBuilder) where T : class { - ODataConventionModelBuilder builder = new ODataConventionModelBuilder(serviceProvider); + ODataConventionModelBuilder builder = new ODataConventionModelBuilder(); builder.EntitySet(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 ( diff --git a/AutoMapper.OData.EFCore.Tests/Model/ModelClasses.cs b/AutoMapper.OData.EFCore.Tests/Model/ModelClasses.cs index 65a7048..0db8d52 100644 --- a/AutoMapper.OData.EFCore.Tests/Model/ModelClasses.cs +++ b/AutoMapper.OData.EFCore.Tests/Model/ModelClasses.cs @@ -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; @@ -31,7 +30,6 @@ public class ProductModel public System.DateTime Birthday { get; set; } public DateTimeOffset NonNullableDiscontinuedDate { get; set; } - [NotFilterable] public DateTimeOffset NotFilterableDiscontinuedDate { get; set; } public DateTimeOffset DiscontinuedOffset { get; set; } @@ -56,7 +54,6 @@ public class ProductModel public int[] AlternateIDs { get; set; } public AddressModel[] AlternateAddresses { get; set; } - [NotFilterable] public AddressModel[] NotFilterableAlternateAddresses { get; set; } } diff --git a/ExpressionBuilder.Tests/Data/DataClasses.cs b/ExpressionBuilder.Tests/Data/DataClasses.cs index 5970535..8dc6bc5 100644 --- a/ExpressionBuilder.Tests/Data/DataClasses.cs +++ b/ExpressionBuilder.Tests/Data/DataClasses.cs @@ -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; @@ -29,7 +28,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; } @@ -54,7 +52,6 @@ public class Product public int[] AlternateIDs { get; set; } public Address[] AlternateAddresses { get; set; } - [NotFilterable] public Address[] NotFilterableAlternateAddresses { get; set; } } diff --git a/ExpressionBuilder.Tests/ExpressionBuilder.Tests.csproj b/ExpressionBuilder.Tests/ExpressionBuilder.Tests.csproj index 90643e4..a495892 100644 --- a/ExpressionBuilder.Tests/ExpressionBuilder.Tests.csproj +++ b/ExpressionBuilder.Tests/ExpressionBuilder.Tests.csproj @@ -7,7 +7,6 @@ - diff --git a/ExpressionBuilder.Tests/FilterTests.cs b/ExpressionBuilder.Tests/FilterTests.cs index c0bf5b0..ba7b1cf 100644 --- a/ExpressionBuilder.Tests/FilterTests.cs +++ b/ExpressionBuilder.Tests/FilterTests.cs @@ -1,8 +1,8 @@ //Adapted from Microsoft.AspNet.OData.Test.Query.Expressions.FilterBinderTests using AutoMapper.AspNet.OData; using ExpressionBuilder.Tests.Data; -using Microsoft.AspNet.OData.Extensions; using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.OData; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.DependencyInjection; using Microsoft.OData; diff --git a/ExpressionBuilder.Tests/ODataHelpers.cs b/ExpressionBuilder.Tests/ODataHelpers.cs index d87ada3..3c2d97e 100644 --- a/ExpressionBuilder.Tests/ODataHelpers.cs +++ b/ExpressionBuilder.Tests/ODataHelpers.cs @@ -1,11 +1,9 @@ using ExpressionBuilder.Tests.Data; -using Microsoft.AspNet.OData; -using Microsoft.AspNet.OData.Builder; -using Microsoft.AspNet.OData.Extensions; -using Microsoft.AspNet.OData.Query; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.OData.Query; using Microsoft.AspNetCore.Routing; using Microsoft.OData.Edm; +using Microsoft.OData.ModelBuilder; using Microsoft.OData.UriParser; using System; using System.Collections.Generic; @@ -23,7 +21,7 @@ private static IEdmModel GetModel(IServiceProvider serviceProvider) where T : if (cachedModels.TryGetValue(modelType, out IEdmModel cachedModel)) return cachedModel; - return GetModel(new ODataConventionModelBuilder(serviceProvider)); + return GetModel(new ODataConventionModelBuilder()); IEdmModel GetModel(ODataConventionModelBuilder builder) { @@ -77,7 +75,7 @@ public static FilterClause GetFilterClause(IDictionary queryO public static FilterClause GetFilterClauseFromFilterOption(IEdmModel model, IEdmEntitySet entitySet, ODataQueryOptionParser parser, string filter) { - Microsoft.AspNet.OData.Routing.ODataPath path = new Microsoft.AspNet.OData.Routing.ODataPath(new EntitySetSegment(entitySet)); + ODataPath path = new ODataPath(new EntitySetSegment(entitySet)); ODataQueryContext context = new ODataQueryContext(model, typeof(DataTypes), path); return new FilterQueryOption(filter, context, parser).FilterClause; @@ -85,14 +83,13 @@ public static FilterClause GetFilterClauseFromFilterOption(IEdmModel model, IEdm public static ODataQueryOptions GetODataQueryOptions(string queryString, IServiceProvider serviceProvider, IRouteBuilder routeBuilder) where T : class { - ODataConventionModelBuilder builder = new ODataConventionModelBuilder(serviceProvider); + ODataConventionModelBuilder builder = new ODataConventionModelBuilder(); builder.EntitySet(typeof(T).Name); IEdmModel model = builder.GetEdmModel(); IEdmEntitySet entitySet = model.EntityContainer.FindEntitySet(typeof(T).Name); - Microsoft.AspNet.OData.Routing.ODataPath path = new Microsoft.AspNet.OData.Routing.ODataPath(new EntitySetSegment(entitySet)); + ODataPath path = new ODataPath(new EntitySetSegment(entitySet)); - routeBuilder.EnableDependencyInjection(); return new ODataQueryOptions ( diff --git a/WebAPI.AspNet.OData.EF6/WebAPI.AspNet.OData.EF6.csproj b/WebAPI.AspNet.OData.EF6/WebAPI.AspNet.OData.EF6.csproj index 7482f8b..985b1f4 100644 --- a/WebAPI.AspNet.OData.EF6/WebAPI.AspNet.OData.EF6.csproj +++ b/WebAPI.AspNet.OData.EF6/WebAPI.AspNet.OData.EF6.csproj @@ -122,7 +122,7 @@ - 2.1.1-alpha.2.3 + 2.1.2-alpha.0.1 4.1.1 diff --git a/WebAPI.OData.EF6/Controllers/OpsTenantController.cs b/WebAPI.OData.EF6/Controllers/OpsTenantController.cs index aefecaa..b65ae4e 100644 --- a/WebAPI.OData.EF6/Controllers/OpsTenantController.cs +++ b/WebAPI.OData.EF6/Controllers/OpsTenantController.cs @@ -2,12 +2,9 @@ using AutoMapper.AspNet.OData; using DAL.EF6; using Domain.OData; -using Microsoft.AspNet.OData; -using Microsoft.AspNet.OData.Query; using Microsoft.AspNetCore.Mvc; -using System; -using System.Collections.Generic; -using System.Linq; +using Microsoft.AspNetCore.OData.Query; +using Microsoft.AspNetCore.OData.Routing.Controllers; using System.Threading.Tasks; namespace WebAPI.OData.EF6.Controllers diff --git a/WebAPI.OData.EF6/Startup.cs b/WebAPI.OData.EF6/Startup.cs index 7b47052..df3f36e 100644 --- a/WebAPI.OData.EF6/Startup.cs +++ b/WebAPI.OData.EF6/Startup.cs @@ -1,21 +1,14 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using AutoMapper; using DAL.EF6; using Domain.OData; -using Microsoft.AspNet.OData.Builder; -using Microsoft.AspNet.OData.Extensions; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.HttpsPolicy; -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.OData; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; using Microsoft.OData.Edm; +using Microsoft.OData.ModelBuilder; namespace WebAPI.OData.EF6 { @@ -32,7 +25,7 @@ public Startup(IConfiguration configuration) public void ConfigureServices(IServiceCollection services) { services.AddControllers(); - services.AddOData(); + services.AddOData(opt => opt.AddModel("", GetEdmModel()).Count().Filter().OrderBy().Expand().Select().SetMaxTop(null)); services.AddScoped ( _ => new MyDbContext @@ -68,8 +61,6 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) app.UseEndpoints(endpoints => { endpoints.MapControllers(); - endpoints.Count().Filter().OrderBy().Expand().Select().MaxTop(null); - endpoints.MapODataRoute("odata", "", GetEdmModel()); }); } diff --git a/WebAPI.OData.EF6/WebAPI.OData.EF6.csproj b/WebAPI.OData.EF6/WebAPI.OData.EF6.csproj index 571cfd8..8a6ba39 100644 --- a/WebAPI.OData.EF6/WebAPI.OData.EF6.csproj +++ b/WebAPI.OData.EF6/WebAPI.OData.EF6.csproj @@ -5,8 +5,7 @@ - - + diff --git a/WebAPI.OData.EFCore/Controllers/OpsTenantController.cs b/WebAPI.OData.EFCore/Controllers/OpsTenantController.cs index 2fa00f8..da34871 100644 --- a/WebAPI.OData.EFCore/Controllers/OpsTenantController.cs +++ b/WebAPI.OData.EFCore/Controllers/OpsTenantController.cs @@ -2,9 +2,9 @@ using AutoMapper.AspNet.OData; using DAL.EFCore; using Domain.OData; -using Microsoft.AspNet.OData; -using Microsoft.AspNet.OData.Query; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.OData.Query; +using Microsoft.AspNetCore.OData.Routing.Controllers; using System.Threading.Tasks; namespace WebAPI.OData.EFCore.Controllers diff --git a/WebAPI.OData.EFCore/Startup.cs b/WebAPI.OData.EFCore/Startup.cs index e9c3e27..4eac0ef 100644 --- a/WebAPI.OData.EFCore/Startup.cs +++ b/WebAPI.OData.EFCore/Startup.cs @@ -1,16 +1,14 @@ using AutoMapper; using DAL.EFCore; using Domain.OData; -using Microsoft.AspNet.OData.Batch; -using Microsoft.AspNet.OData.Builder; -using Microsoft.AspNet.OData.Extensions; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.OData; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using System.Linq; +using Microsoft.OData.Edm; +using Microsoft.OData.ModelBuilder; namespace WebAPI.OData.EFCore { @@ -28,7 +26,8 @@ public Startup(IConfiguration configuration) public void ConfigureServices(IServiceCollection services) { services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); - services.AddOData(); + services.AddControllers(); + services.AddOData(opt => opt.AddModel("", GetEdmModel()).Count().Filter().OrderBy().Expand().Select().SetMaxTop(null)); services.AddSingleton ( @@ -39,14 +38,6 @@ public void ConfigureServices(IServiceCollection services) }) ) .AddScoped(sp => new Mapper(sp.GetRequiredService(), sp.GetService)); - - services.AddMvc(options => - { - // https://blogs.msdn.microsoft.com/webdev/2018/08/27/asp-net-core-2-2-0-preview1-endpoint-routing/ - // Because conflicts with ODataRouting as of this version - // could improve performance though - options.EnableEndpointRouting = false; - }).SetCompatibilityVersion(CompatibilityVersion.Version_3_0); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. @@ -58,22 +49,26 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) } app.UseHttpsRedirection(); - app.UseCors(); - app.UseODataBatching(); - app.UseMvc(r => { + app.UseRouting(); + app.UseAuthorization(); - var builder = new ODataConventionModelBuilder(); - builder.EntitySet(nameof(OpsTenant)); - builder.EntitySet(nameof(CoreBuilding)); - builder.EntitySet(nameof(OpsBuilder)); - builder.EntitySet(nameof(OpsCity)); - var model = builder.GetEdmModel(); - r.Count().Filter().OrderBy().Expand().Select().MaxTop(null); - r.MapODataServiceRoute("odata", "", model, new DefaultODataBatchHandler()); - + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); }); } + + private IEdmModel GetEdmModel() + { + var builder = new ODataConventionModelBuilder(); + builder.EntitySet(nameof(OpsTenant)); + builder.EntitySet(nameof(CoreBuilding)); + builder.EntitySet(nameof(OpsBuilder)); + builder.EntitySet(nameof(OpsCity)); + + return builder.GetEdmModel(); + } } } diff --git a/WebAPI.OData.EFCore/WebAPI.OData.EFCore.csproj b/WebAPI.OData.EFCore/WebAPI.OData.EFCore.csproj index c583a08..3206176 100644 --- a/WebAPI.OData.EFCore/WebAPI.OData.EFCore.csproj +++ b/WebAPI.OData.EFCore/WebAPI.OData.EFCore.csproj @@ -5,9 +5,8 @@ - + -