diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 57fd492..c820268 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,7 +19,7 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v4 with: - dotnet-version: 10.x + dotnet-version: 11.x - name: Set Variables run: | diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 88826cc..497d739 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,7 +17,7 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v4 with: - dotnet-version: 10.x + dotnet-version: 11.x - name: Set Variables run: | diff --git a/AutoMapper.AspNetCore.OData.EFCore/AutoMapper.AspNetCore.OData.EFCore.csproj b/AutoMapper.AspNetCore.OData.EFCore/AutoMapper.AspNetCore.OData.EFCore.csproj index 0f007ea..59b73f6 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 @@  - net8.0;net9.0;net10.0 + net10.0;net11.0 AutoMapper.AspNet.OData AutoMapper.AspNetCore.OData.EFCore Creates LINQ expressions from ODataQueryOptions and executes the query. false - Removing obsolete methods and using the latest version of AutoMapper.Extensions.ExpressionMapping. Ending maintenance for AutoMapper.AspNetCore.OData.EF6. + Supporting AutoMapper v17 and .NET v11. linq expressions odata efcore icon.png https://github.com/AutoMapper/AutoMapper.Extensions.OData @@ -30,26 +30,22 @@ - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + - - + + - - - - - - + + diff --git a/AutoMapper.Extensions.OData.sln b/AutoMapper.Extensions.OData.sln index 9c59675..a66a1b0 100644 --- a/AutoMapper.Extensions.OData.sln +++ b/AutoMapper.Extensions.OData.sln @@ -23,6 +23,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution ProjectSection(SolutionItems) = preProject .github\workflows\ci.yml = .github\workflows\ci.yml Directory.Build.props = Directory.Build.props + global.json = global.json Pack_Push.ps1 = Pack_Push.ps1 .github\workflows\release.yml = .github\workflows\release.yml EndProjectSection diff --git a/AutoMapper.OData.EFCore.Tests/AutoMapper.OData.EFCore.Tests.csproj b/AutoMapper.OData.EFCore.Tests/AutoMapper.OData.EFCore.Tests.csproj index ac68450..f5695b7 100644 --- a/AutoMapper.OData.EFCore.Tests/AutoMapper.OData.EFCore.Tests.csproj +++ b/AutoMapper.OData.EFCore.Tests/AutoMapper.OData.EFCore.Tests.csproj @@ -1,16 +1,17 @@  - net10.0 + net11.0 false - - - - + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/DAL.EFCore/DAL.EFCore.csproj b/DAL.EFCore/DAL.EFCore.csproj index 46498ce..b63826c 100644 --- a/DAL.EFCore/DAL.EFCore.csproj +++ b/DAL.EFCore/DAL.EFCore.csproj @@ -1,19 +1,15 @@  - net8.0;net9.0;net10.0 + net10.0;net11.0 - - - - - - + + - - + + diff --git a/ExpressionBuilder.Tests/ExpressionBuilder.Tests.csproj b/ExpressionBuilder.Tests/ExpressionBuilder.Tests.csproj index 63bed2d..ea7c1d4 100644 --- a/ExpressionBuilder.Tests/ExpressionBuilder.Tests.csproj +++ b/ExpressionBuilder.Tests/ExpressionBuilder.Tests.csproj @@ -1,15 +1,15 @@  - net10.0 + net11.0 false - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/ExpressionBuilder.Tests/FilterTests.cs b/ExpressionBuilder.Tests/FilterTests.cs index 8c73d9f..325240d 100644 --- a/ExpressionBuilder.Tests/FilterTests.cs +++ b/ExpressionBuilder.Tests/FilterTests.cs @@ -1327,9 +1327,9 @@ public void TimeOnlyFunctions_NonNullable(string filterString, string expression } [Theory] - [InlineData("fractionalseconds(DiscontinuedDate) eq 0.2", "$it => ((Convert($it.DiscontinuedDate.Value.Millisecond) / 1000) == 0.2)")] - [InlineData("fractionalseconds(NullableTimeOfDayProperty) eq 0.2", "$it => ((Convert($it.NullableTimeOfDayProperty.Value.Milliseconds) / 1000) == 0.2)")] - [InlineData("fractionalseconds(NullableTimeOnlyProperty) eq 0.2", "$it => ((Convert($it.NullableTimeOnlyProperty.Value.Millisecond) / 1000) == 0.2)")] + [InlineData("fractionalseconds(DiscontinuedDate) eq 0.2", "$it => ((Convert($it.DiscontinuedDate.Value.Millisecond) / 1000) == 0.20000000298023223876953125)")]//OData FilterCluase constant returns higher precision in .NET 11 + [InlineData("fractionalseconds(NullableTimeOfDayProperty) eq 0.2", "$it => ((Convert($it.NullableTimeOfDayProperty.Value.Milliseconds) / 1000) == 0.20000000298023223876953125)")] + [InlineData("fractionalseconds(NullableTimeOnlyProperty) eq 0.2", "$it => ((Convert($it.NullableTimeOnlyProperty.Value.Millisecond) / 1000) == 0.20000000298023223876953125)")] public void FractionalsecondsFunction_Nullable(string filterString, string expression) { //act @@ -1340,9 +1340,9 @@ public void FractionalsecondsFunction_Nullable(string filterString, string expre } [Theory] - [InlineData("fractionalseconds(NonNullableDiscontinuedDate) eq 0.2", "$it => ((Convert($it.NonNullableDiscontinuedDate.Millisecond) / 1000) == 0.2)")] - [InlineData("fractionalseconds(TimeOfDayProperty) eq 0.2", "$it => ((Convert($it.TimeOfDayProperty.Milliseconds) / 1000) == 0.2)")] - [InlineData("fractionalseconds(TimeOnlyProperty) eq 0.2", "$it => ((Convert($it.TimeOnlyProperty.Millisecond) / 1000) == 0.2)")] + [InlineData("fractionalseconds(NonNullableDiscontinuedDate) eq 0.2", "$it => ((Convert($it.NonNullableDiscontinuedDate.Millisecond) / 1000) == 0.20000000298023223876953125)")]//OData FilterCluase constant returns higher precision in .NET 11 + [InlineData("fractionalseconds(TimeOfDayProperty) eq 0.2", "$it => ((Convert($it.TimeOfDayProperty.Milliseconds) / 1000) == 0.20000000298023223876953125)")] + [InlineData("fractionalseconds(TimeOnlyProperty) eq 0.2", "$it => ((Convert($it.TimeOnlyProperty.Millisecond) / 1000) == 0.20000000298023223876953125)")] public void FractionalsecondsFunction_NonNullable(string filterString, string expression) { //act diff --git a/MigrationTool/MigrationTool.csproj b/MigrationTool/MigrationTool.csproj index 954fcf3..f80df7a 100644 --- a/MigrationTool/MigrationTool.csproj +++ b/MigrationTool/MigrationTool.csproj @@ -2,17 +2,17 @@ Exe - net10.0 + net11.0 - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + diff --git a/SeedDatabase/SeedDatabase.csproj b/SeedDatabase/SeedDatabase.csproj index 8d08bc8..4d5c245 100644 --- a/SeedDatabase/SeedDatabase.csproj +++ b/SeedDatabase/SeedDatabase.csproj @@ -2,13 +2,13 @@ Exe - net10.0 + net11.0 - - - + + + diff --git a/Web.Tests/Web.Tests.csproj b/Web.Tests/Web.Tests.csproj index e7dc576..e295986 100644 --- a/Web.Tests/Web.Tests.csproj +++ b/Web.Tests/Web.Tests.csproj @@ -1,18 +1,18 @@  - net9.0 + net11.0 false - - - - - - + + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/WebAPI.OData.EFCore/Program.cs b/WebAPI.OData.EFCore/Program.cs index 7dc6943..d62810c 100644 --- a/WebAPI.OData.EFCore/Program.cs +++ b/WebAPI.OData.EFCore/Program.cs @@ -1,24 +1,59 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore; -using Microsoft.AspNetCore.Hosting; +using AutoMapper; +using DAL.EFCore; +using Domain.OData; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.OData; +using Microsoft.AspNetCore.OData.Query.Expressions; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging.Abstractions; +using Microsoft.OData.Edm; +using Microsoft.OData.ModelBuilder; +using WebAPI.OData.EFCore.Binders; +using WebAPI.OData.EFCore.Controllers; -namespace WebAPI.OData.EFCore -{ - public class Program +var builder = WebApplication.CreateBuilder(args); + +builder.Services.AddDbContext(options => options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection"))); +builder.Services.AddControllers() + .AddOData(opt => opt.EnableQueryFeatures() + .AddRouteComponents("", GetEdmModel(), services => services.AddSingleton())); +builder.Services.AddSingleton +( + new MapperConfiguration(cfg => { - public static void Main(string[] args) - { - CreateWebHostBuilder(args).Build().Run(); - } - - public static IWebHostBuilder CreateWebHostBuilder(string[] args) => - WebHost.CreateDefaultBuilder(args) - .UseStartup(); - } + cfg.AddMaps(typeof(ValuesController).Assembly); + cfg.AllowNullCollections = true; + }, new NullLoggerFactory()) +) +.AddScoped(sp => new Mapper(sp.GetRequiredService(), sp.GetService)); + +var app = builder.Build(); + +if (builder.Environment.EnvironmentName == "Development") +{ + app.UseDeveloperExceptionPage(); } + +app.UseHttpsRedirection(); + +app.UseRouting(); + +app.UseAuthorization(); + +app.MapControllers(); + +await app.RunAsync(); + +static IEdmModel GetEdmModel() +{ + var builder = new ODataConventionModelBuilder(); + builder.EnableLowerCamelCase(); + builder.EntitySet(nameof(OpsTenant)); + builder.EntitySet(nameof(CoreBuilding)); + builder.EntitySet(nameof(OpsBuilder)); + builder.EntitySet(nameof(OpsCity)); + + return builder.GetEdmModel(); +} \ No newline at end of file diff --git a/WebAPI.OData.EFCore/Startup.cs b/WebAPI.OData.EFCore/Startup.cs deleted file mode 100644 index ae35f0d..0000000 --- a/WebAPI.OData.EFCore/Startup.cs +++ /dev/null @@ -1,80 +0,0 @@ -using AutoMapper; -using DAL.EFCore; -using Domain.OData; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.OData; -using Microsoft.AspNetCore.OData.Query.Expressions; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging.Abstractions; -using Microsoft.OData.Edm; -using Microsoft.OData.ModelBuilder; -using WebAPI.OData.EFCore.Binders; -using WebAPI.OData.EFCore.Mappings; - -namespace WebAPI.OData.EFCore -{ - public class Startup - { - public Startup(IConfiguration configuration) - { - Configuration = configuration; - } - - public IConfiguration Configuration { get; } - - // This method gets called by the runtime. Use this method to add services to the container. - //Rebuild - public void ConfigureServices(IServiceCollection services) - { - services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); - services.AddControllers() - .AddOData(opt => opt.EnableQueryFeatures() - .AddRouteComponents("", GetEdmModel(), services => services.AddSingleton())); - services.AddSingleton - ( - new MapperConfiguration(cfg => - { - cfg.AddMaps(typeof(Startup).Assembly); - cfg.AllowNullCollections = true; - }, new NullLoggerFactory()) - ) - .AddScoped(sp => new Mapper(sp.GetRequiredService(), sp.GetService)); - } - - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - if (env.EnvironmentName == "Development") - { - app.UseDeveloperExceptionPage(); - } - - app.UseHttpsRedirection(); - - app.UseRouting(); - - app.UseAuthorization(); - - app.UseEndpoints(endpoints => - { - endpoints.MapControllers(); - }); - } - - private IEdmModel GetEdmModel() - { - var builder = new ODataConventionModelBuilder(); - builder.EnableLowerCamelCase(); - //builder.Namespace = "com.FooBar"; - 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 0812253..403b96f 100644 --- a/WebAPI.OData.EFCore/WebAPI.OData.EFCore.csproj +++ b/WebAPI.OData.EFCore/WebAPI.OData.EFCore.csproj @@ -1,12 +1,12 @@  - net10.0 + net11.0 - - + + diff --git a/global.json b/global.json new file mode 100644 index 0000000..802ab21 --- /dev/null +++ b/global.json @@ -0,0 +1,5 @@ +{ + "test": { + "runner": "Microsoft.Testing.Platform" + } +} \ No newline at end of file