Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ jobs:
runs-on: windows-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup .NET Core
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v4
with:
dotnet-version: 10.x

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ jobs:
runs-on: windows-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup .NET Core
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v4
with:
dotnet-version: 10.x

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<PackageId>AutoMapper.AspNetCore.OData.EF6</PackageId>
<Description>Creates LINQ expressions from ODataQueryOptions and executes the query.</Description>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageReleaseNotes>Supporting AutoMapper v16 (EF Core only).</PackageReleaseNotes>
<PackageReleaseNotes>Marking obsolete methods (EF Core only).</PackageReleaseNotes>
<PackageTags>linq expressions odata efcore</PackageTags>
<PackageIcon>icon.png</PackageIcon>
<RepositoryUrl>https://github.com/AutoMapper/AutoMapper.Extensions.OData</RepositoryUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<PackageId>AutoMapper.AspNetCore.OData.EFCore</PackageId>
<Description>Creates LINQ expressions from ODataQueryOptions and executes the query.</Description>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageReleaseNotes>Supporting AutoMapper v16 (EF Core only).</PackageReleaseNotes>
<PackageReleaseNotes>Marking obsolete methods (EF Core only).</PackageReleaseNotes>
<PackageTags>linq expressions odata efcore</PackageTags>
<PackageIcon>icon.png</PackageIcon>
<RepositoryUrl>https://github.com/AutoMapper/AutoMapper.Extensions.OData</RepositoryUrl>
Expand All @@ -30,7 +30,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="AutoMapper.Extensions.ExpressionMapping" Version="[10.0.0,11.0.0)" />
<PackageReference Include="AutoMapper.Extensions.ExpressionMapping" Version="[10.1.0,11.0.0)" />
<PackageReference Include="LogicBuilder.Expressions.Utils" Version="7.0.0" />
<PackageReference Include="Microsoft.AspNetCore.OData" Version="9.4.1" />
<PackageReference Include="MinVer" Version="6.0.0">
Expand Down
5 changes: 4 additions & 1 deletion AutoMapper.AspNetCore.OData.EFCore/QueryableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
{
public static class QueryableExtensions
{
[Obsolete("Use \"Task<IQueryable<TModel>> GetQueryAsync<TModel, TData>(this IQueryable<TData> query, IMapper mapper, ODataQueryOptions<TModel> options, QuerySettings querySettings = null)\" or \"IQueryable<TModel> GetQuery<TModel, TData>(this IQueryable<TData> query, IMapper mapper, ODataQueryOptions<TModel> options, QuerySettings querySettings = null)\" instead.")]
public static ICollection<TModel> Get<TModel, TData>(this IQueryable<TData> query, IMapper mapper, ODataQueryOptions<TModel> options, QuerySettings querySettings = null)
where TModel : class
{
Expand All @@ -31,6 +32,7 @@
);
}

[Obsolete("Use \"Task<IQueryable<TModel>> GetQueryAsync<TModel, TData>(this IQueryable<TData> query, IMapper mapper, ODataQueryOptions<TModel> options, QuerySettings querySettings = null)\" or \"IQueryable<TModel> GetQuery<TModel, TData>(this IQueryable<TData> query, IMapper mapper, ODataQueryOptions<TModel> options, QuerySettings querySettings = null)\" instead.")]
public static async Task<ICollection<TModel>> GetAsync<TModel, TData>(this IQueryable<TData> query, IMapper mapper, ODataQueryOptions<TModel> options, QuerySettings querySettings = null)
where TModel : class
{
Expand Down Expand Up @@ -72,6 +74,7 @@
return query.GetQueryable(mapper, options, querySettings, filter);
}

[Obsolete("This method was meant for internal use. The equivalent GetQueryable methods are private.")]
public static ICollection<TModel> Get<TModel, TData>(this IQueryable<TData> query, IMapper mapper,
Expression<Func<TModel, bool>> filter = null,
Expression<Func<IQueryable<TModel>, IQueryable<TModel>>> queryFunc = null,
Expand All @@ -81,7 +84,7 @@
query.GetDataQuery(mapper, filter, queryFunc, includeProperties).ToList()
).ToList();


[Obsolete("This method was meant for internal use. The equivalent GetQueryable methods are private.")]
public static async Task<ICollection<TModel>> GetAsync<TModel, TData>(this IQueryable<TData> query, IMapper mapper,
Expression<Func<TModel, bool>> filter = null,
Expression<Func<IQueryable<TModel>, IQueryable<TModel>>> queryFunc = null,
Expand Down Expand Up @@ -111,7 +114,7 @@
{
Expression<Func<TData, bool>> f = mapper.MapExpression<Expression<Func<TData, bool>>>(filter);
Func<IQueryable<TData>, IQueryable<TData>> mappedQueryFunc = mapper.MapExpression<Expression<Func<IQueryable<TData>, IQueryable<TData>>>>(queryFunc)?.Compile();
ICollection<Expression<Func<IQueryable<TData>, IIncludableQueryable<TData, object>>>> includes = mapper.MapIncludesList<Expression<Func<IQueryable<TData>, IIncludableQueryable<TData, object>>>>(includeProperties);

Check warning on line 117 in AutoMapper.AspNetCore.OData.EFCore/QueryableExtensions.cs

View workflow job for this annotation

GitHub Actions / build

'MapperExtensions.MapIncludesList<TDestDelegate>(IMapper, IEnumerable<LambdaExpression>)' is obsolete: 'Use ProjectTo with expansions instead of IMapper.MapIncludesList.'

Check warning on line 117 in AutoMapper.AspNetCore.OData.EFCore/QueryableExtensions.cs

View workflow job for this annotation

GitHub Actions / build

'MapperExtensions.MapIncludesList<TDestDelegate>(IMapper, IEnumerable<LambdaExpression>)' is obsolete: 'Use ProjectTo with expansions instead of IMapper.MapIncludesList.'

Check warning on line 117 in AutoMapper.AspNetCore.OData.EFCore/QueryableExtensions.cs

View workflow job for this annotation

GitHub Actions / build

'MapperExtensions.MapIncludesList<TDestDelegate>(IMapper, IEnumerable<LambdaExpression>)' is obsolete: 'Use ProjectTo with expansions instead of IMapper.MapIncludesList.'

Check warning on line 117 in AutoMapper.AspNetCore.OData.EFCore/QueryableExtensions.cs

View workflow job for this annotation

GitHub Actions / build

'MapperExtensions.MapIncludesList<TDestDelegate>(IMapper, IEnumerable<LambdaExpression>)' is obsolete: 'Use ProjectTo with expansions instead of IMapper.MapIncludesList.'

Check warning on line 117 in AutoMapper.AspNetCore.OData.EFCore/QueryableExtensions.cs

View workflow job for this annotation

GitHub Actions / build

'MapperExtensions.MapIncludesList<TDestDelegate>(IMapper, IEnumerable<LambdaExpression>)' is obsolete: 'Use ProjectTo with expansions instead of IMapper.MapIncludesList.'

Check warning on line 117 in AutoMapper.AspNetCore.OData.EFCore/QueryableExtensions.cs

View workflow job for this annotation

GitHub Actions / build

'MapperExtensions.MapIncludesList<TDestDelegate>(IMapper, IEnumerable<LambdaExpression>)' is obsolete: 'Use ProjectTo with expansions instead of IMapper.MapIncludesList.'

if (filter != null)
query = query.Where(f);
Expand Down
2 changes: 1 addition & 1 deletion AutoMapper.OData.EFCore.Tests/ExpansionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public ExpansionTestsFixture()
),
ServiceLifetime.Transient
)
.AddSingleton<IConfigurationProvider>(new MapperConfiguration(cfg => cfg.AddMaps(typeof(GetTests).Assembly), new NullLoggerFactory()))
.AddSingleton<IConfigurationProvider>(new MapperConfiguration(cfg => cfg.AddMaps(typeof(GetQueryTests).Assembly), new NullLoggerFactory()))
.AddTransient<IMapper>(sp => new Mapper(sp.GetRequiredService<IConfigurationProvider>(), sp.GetService))
.AddTransient<IApplicationBuilder>(sp => new ApplicationBuilder(sp))
.AddRouting()
Expand Down
2 changes: 1 addition & 1 deletion AutoMapper.OData.EFCore.Tests/GetQuerySelectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public GetQuerySelectTestsFixture()
),
ServiceLifetime.Transient
)
.AddSingleton<IConfigurationProvider>(new MapperConfiguration(cfg => cfg.AddMaps(typeof(GetTests).Assembly), new NullLoggerFactory()))
.AddSingleton<IConfigurationProvider>(new MapperConfiguration(cfg => cfg.AddMaps(typeof(GetQueryTests).Assembly), new NullLoggerFactory()))
.AddTransient<IMapper>(sp => new Mapper(sp.GetRequiredService<IConfigurationProvider>(), sp.GetService))
.AddTransient<IApplicationBuilder>(sp => new ApplicationBuilder(sp))
.AddRouting()
Expand Down
87 changes: 86 additions & 1 deletion AutoMapper.OData.EFCore.Tests/GetQueryTests.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
using AutoMapper.AspNet.OData;
using AutoMapper.OData.EFCore.Tests.Binders;
using AutoMapper.OData.EFCore.Tests.Data;
using AutoMapper.OData.EFCore.Tests.Model;
using DAL.EFCore;
using Domain.OData;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.ApplicationParts;
using Microsoft.AspNetCore.OData;
using Microsoft.AspNetCore.OData.Extensions;
using Microsoft.AspNetCore.OData.Query;
using Microsoft.AspNetCore.OData.Query.Expressions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging.Abstractions;
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 @@ -2000,7 +2007,7 @@ public GetQueryTestsFixture()
),
ServiceLifetime.Transient
)
.AddSingleton<IConfigurationProvider>(new MapperConfiguration(cfg => cfg.AddMaps(typeof(GetTests).Assembly), new NullLoggerFactory()))
.AddSingleton<IConfigurationProvider>(new MapperConfiguration(cfg => cfg.AddMaps(typeof(GetQueryTests).Assembly), new NullLoggerFactory()))
.AddTransient<IMapper>(sp => new Mapper(sp.GetRequiredService<IConfigurationProvider>(), sp.GetService))
.AddTransient<IApplicationBuilder>(sp => new ApplicationBuilder(sp))
.AddRouting()
Expand All @@ -2016,4 +2023,82 @@ public GetQueryTestsFixture()

internal IServiceProvider ServiceProvider;
}

public static class ODataHelpers
{
public static ODataQueryOptions<T> GetODataQueryOptions<T>(string queryString, IServiceProvider serviceProvider, string customNamespace = null, bool enableLowerCamelCase = false) where T : class
{
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
if (customNamespace != null)
builder.Namespace = customNamespace;

if (enableLowerCamelCase)
builder.EnableLowerCamelCase();

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

var oDataQueryOptions = new ODataQueryOptions<T>
(
new ODataQueryContext(model, typeof(T), path),
BuildRequest(serviceProvider, model, new Uri(BASEADDRESS + queryString))
);

return oDataQueryOptions;
}

public static ODataQueryOptions<Model.CategoryModel> GetODataQueryOptionsWithDuplicateEntityName(string queryString, IServiceProvider serviceProvider, string customNamespace = null)
{
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
if (customNamespace != null)
builder.Namespace = customNamespace;

builder.EnableLowerCamelCase();

builder.EntitySet<X.CategoryModel>(typeof(X.CategoryModel).Name + "X");
builder.EntitySet<Model.CategoryModel>(nameof(Model.CategoryModel));
IEdmModel model = builder.GetEdmModel();
IEdmEntitySet entitySet = model.EntityContainer.FindEntitySet(typeof(Model.CategoryModel).Name);
ODataPath path = new ODataPath(new EntitySetSegment(entitySet));

var oDataQueryOptions = new ODataQueryOptions<Model.CategoryModel>
(
new ODataQueryContext(model, typeof(Model.CategoryModel), path),
BuildRequest(serviceProvider, model, new Uri(BASEADDRESS + queryString))
);

return oDataQueryOptions;
}

static HttpRequest BuildRequest(IServiceProvider serviceProvider, IEdmModel model, Uri uri)
{
var request = new DefaultHttpContext()
{
RequestServices = serviceProvider
}.Request;

var oDataOptions = new ODataOptions().AddRouteComponents("key", model,
x => x.AddSingleton<ISearchBinder, OpsTenantSearchBinder>());
var (_, routeProvider) = oDataOptions.RouteComponents["key"];

request.ODataFeature().Services = routeProvider;

request.Method = "GET";
request.Host = new HostString(uri.Host, uri.Port);
request.Path = uri.LocalPath;
request.QueryString = new QueryString(uri.Query);

return request;
}

static readonly string BASEADDRESS = "http://localhost:16324";
}

internal class TestMvcCoreBuilder : IMvcCoreBuilder
{
public ApplicationPartManager PartManager { get; set; }
public IServiceCollection Services { get; set; }
}
}
Loading
Loading