Skip to content

Commit 4819482

Browse files
authored
Marking obsolete methods. Bumps the minimum version of AutoMapper.Extensions.ExpressionMapping to10.1.0. (#250)
1 parent 59825ac commit 4819482

9 files changed

Lines changed: 99 additions & 807 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ jobs:
1212
runs-on: windows-latest
1313

1414
steps:
15-
- uses: actions/checkout@v2
15+
- uses: actions/checkout@v4
1616
with:
1717
fetch-depth: 0
1818

1919
- name: Setup .NET Core
20-
uses: actions/setup-dotnet@v1
20+
uses: actions/setup-dotnet@v4
2121
with:
2222
dotnet-version: 10.x
2323

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ jobs:
1010
runs-on: windows-latest
1111

1212
steps:
13-
- uses: actions/checkout@v2
13+
- uses: actions/checkout@v4
1414
with:
1515
fetch-depth: 0
1616

1717
- name: Setup .NET Core
18-
uses: actions/setup-dotnet@v1
18+
uses: actions/setup-dotnet@v4
1919
with:
2020
dotnet-version: 10.x
2121

AutoMapper.AspNetCore.OData.EF6/AutoMapper.AspNetCore.OData.EF6.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<PackageId>AutoMapper.AspNetCore.OData.EF6</PackageId>
77
<Description>Creates LINQ expressions from ODataQueryOptions and executes the query.</Description>
88
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
9-
<PackageReleaseNotes>Supporting AutoMapper v16 (EF Core only).</PackageReleaseNotes>
9+
<PackageReleaseNotes>Marking obsolete methods (EF Core only).</PackageReleaseNotes>
1010
<PackageTags>linq expressions odata efcore</PackageTags>
1111
<PackageIcon>icon.png</PackageIcon>
1212
<RepositoryUrl>https://github.com/AutoMapper/AutoMapper.Extensions.OData</RepositoryUrl>

AutoMapper.AspNetCore.OData.EFCore/AutoMapper.AspNetCore.OData.EFCore.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<PackageId>AutoMapper.AspNetCore.OData.EFCore</PackageId>
77
<Description>Creates LINQ expressions from ODataQueryOptions and executes the query.</Description>
88
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
9-
<PackageReleaseNotes>Supporting AutoMapper v16 (EF Core only).</PackageReleaseNotes>
9+
<PackageReleaseNotes>Marking obsolete methods (EF Core only).</PackageReleaseNotes>
1010
<PackageTags>linq expressions odata efcore</PackageTags>
1111
<PackageIcon>icon.png</PackageIcon>
1212
<RepositoryUrl>https://github.com/AutoMapper/AutoMapper.Extensions.OData</RepositoryUrl>
@@ -30,7 +30,7 @@
3030
</ItemGroup>
3131

3232
<ItemGroup>
33-
<PackageReference Include="AutoMapper.Extensions.ExpressionMapping" Version="[10.0.0,11.0.0)" />
33+
<PackageReference Include="AutoMapper.Extensions.ExpressionMapping" Version="[10.1.0,11.0.0)" />
3434
<PackageReference Include="LogicBuilder.Expressions.Utils" Version="7.0.0" />
3535
<PackageReference Include="Microsoft.AspNetCore.OData" Version="9.4.1" />
3636
<PackageReference Include="MinVer" Version="6.0.0">

AutoMapper.AspNetCore.OData.EFCore/QueryableExtensions.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace AutoMapper.AspNet.OData
1313
{
1414
public static class QueryableExtensions
1515
{
16+
[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.")]
1617
public static ICollection<TModel> Get<TModel, TData>(this IQueryable<TData> query, IMapper mapper, ODataQueryOptions<TModel> options, QuerySettings querySettings = null)
1718
where TModel : class
1819
{
@@ -31,6 +32,7 @@ public static ICollection<TModel> Get<TModel, TData>(this IQueryable<TData> quer
3132
);
3233
}
3334

35+
[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.")]
3436
public static async Task<ICollection<TModel>> GetAsync<TModel, TData>(this IQueryable<TData> query, IMapper mapper, ODataQueryOptions<TModel> options, QuerySettings querySettings = null)
3537
where TModel : class
3638
{
@@ -72,6 +74,7 @@ public static IQueryable<TModel> GetQuery<TModel, TData>(this IQueryable<TData>
7274
return query.GetQueryable(mapper, options, querySettings, filter);
7375
}
7476

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

84-
87+
[Obsolete("This method was meant for internal use. The equivalent GetQueryable methods are private.")]
8588
public static async Task<ICollection<TModel>> GetAsync<TModel, TData>(this IQueryable<TData> query, IMapper mapper,
8689
Expression<Func<TModel, bool>> filter = null,
8790
Expression<Func<IQueryable<TModel>, IQueryable<TModel>>> queryFunc = null,

AutoMapper.OData.EFCore.Tests/ExpansionTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public ExpansionTestsFixture()
218218
),
219219
ServiceLifetime.Transient
220220
)
221-
.AddSingleton<IConfigurationProvider>(new MapperConfiguration(cfg => cfg.AddMaps(typeof(GetTests).Assembly), new NullLoggerFactory()))
221+
.AddSingleton<IConfigurationProvider>(new MapperConfiguration(cfg => cfg.AddMaps(typeof(GetQueryTests).Assembly), new NullLoggerFactory()))
222222
.AddTransient<IMapper>(sp => new Mapper(sp.GetRequiredService<IConfigurationProvider>(), sp.GetService))
223223
.AddTransient<IApplicationBuilder>(sp => new ApplicationBuilder(sp))
224224
.AddRouting()

AutoMapper.OData.EFCore.Tests/GetQuerySelectTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public GetQuerySelectTestsFixture()
214214
),
215215
ServiceLifetime.Transient
216216
)
217-
.AddSingleton<IConfigurationProvider>(new MapperConfiguration(cfg => cfg.AddMaps(typeof(GetTests).Assembly), new NullLoggerFactory()))
217+
.AddSingleton<IConfigurationProvider>(new MapperConfiguration(cfg => cfg.AddMaps(typeof(GetQueryTests).Assembly), new NullLoggerFactory()))
218218
.AddTransient<IMapper>(sp => new Mapper(sp.GetRequiredService<IConfigurationProvider>(), sp.GetService))
219219
.AddTransient<IApplicationBuilder>(sp => new ApplicationBuilder(sp))
220220
.AddRouting()

AutoMapper.OData.EFCore.Tests/GetQueryTests.cs

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
using AutoMapper.AspNet.OData;
2+
using AutoMapper.OData.EFCore.Tests.Binders;
23
using AutoMapper.OData.EFCore.Tests.Data;
34
using AutoMapper.OData.EFCore.Tests.Model;
45
using DAL.EFCore;
56
using Domain.OData;
67
using Microsoft.AspNetCore.Builder;
8+
using Microsoft.AspNetCore.Http;
9+
using Microsoft.AspNetCore.Mvc.ApplicationParts;
710
using Microsoft.AspNetCore.OData;
811
using Microsoft.AspNetCore.OData.Extensions;
912
using Microsoft.AspNetCore.OData.Query;
13+
using Microsoft.AspNetCore.OData.Query.Expressions;
1014
using Microsoft.EntityFrameworkCore;
1115
using Microsoft.Extensions.DependencyInjection;
1216
using Microsoft.Extensions.Logging.Abstractions;
17+
using Microsoft.OData.Edm;
18+
using Microsoft.OData.ModelBuilder;
19+
using Microsoft.OData.UriParser;
1320
using System;
1421
using System.Collections.Generic;
1522
using System.Linq;
@@ -2000,7 +2007,7 @@ public GetQueryTestsFixture()
20002007
),
20012008
ServiceLifetime.Transient
20022009
)
2003-
.AddSingleton<IConfigurationProvider>(new MapperConfiguration(cfg => cfg.AddMaps(typeof(GetTests).Assembly), new NullLoggerFactory()))
2010+
.AddSingleton<IConfigurationProvider>(new MapperConfiguration(cfg => cfg.AddMaps(typeof(GetQueryTests).Assembly), new NullLoggerFactory()))
20042011
.AddTransient<IMapper>(sp => new Mapper(sp.GetRequiredService<IConfigurationProvider>(), sp.GetService))
20052012
.AddTransient<IApplicationBuilder>(sp => new ApplicationBuilder(sp))
20062013
.AddRouting()
@@ -2016,4 +2023,82 @@ public GetQueryTestsFixture()
20162023

20172024
internal IServiceProvider ServiceProvider;
20182025
}
2026+
2027+
public static class ODataHelpers
2028+
{
2029+
public static ODataQueryOptions<T> GetODataQueryOptions<T>(string queryString, IServiceProvider serviceProvider, string customNamespace = null, bool enableLowerCamelCase = false) where T : class
2030+
{
2031+
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
2032+
if (customNamespace != null)
2033+
builder.Namespace = customNamespace;
2034+
2035+
if (enableLowerCamelCase)
2036+
builder.EnableLowerCamelCase();
2037+
2038+
builder.EntitySet<T>(typeof(T).Name);
2039+
IEdmModel model = builder.GetEdmModel();
2040+
IEdmEntitySet entitySet = model.EntityContainer.FindEntitySet(typeof(T).Name);
2041+
ODataPath path = new ODataPath(new EntitySetSegment(entitySet));
2042+
2043+
var oDataQueryOptions = new ODataQueryOptions<T>
2044+
(
2045+
new ODataQueryContext(model, typeof(T), path),
2046+
BuildRequest(serviceProvider, model, new Uri(BASEADDRESS + queryString))
2047+
);
2048+
2049+
return oDataQueryOptions;
2050+
}
2051+
2052+
public static ODataQueryOptions<Model.CategoryModel> GetODataQueryOptionsWithDuplicateEntityName(string queryString, IServiceProvider serviceProvider, string customNamespace = null)
2053+
{
2054+
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
2055+
if (customNamespace != null)
2056+
builder.Namespace = customNamespace;
2057+
2058+
builder.EnableLowerCamelCase();
2059+
2060+
builder.EntitySet<X.CategoryModel>(typeof(X.CategoryModel).Name + "X");
2061+
builder.EntitySet<Model.CategoryModel>(nameof(Model.CategoryModel));
2062+
IEdmModel model = builder.GetEdmModel();
2063+
IEdmEntitySet entitySet = model.EntityContainer.FindEntitySet(typeof(Model.CategoryModel).Name);
2064+
ODataPath path = new ODataPath(new EntitySetSegment(entitySet));
2065+
2066+
var oDataQueryOptions = new ODataQueryOptions<Model.CategoryModel>
2067+
(
2068+
new ODataQueryContext(model, typeof(Model.CategoryModel), path),
2069+
BuildRequest(serviceProvider, model, new Uri(BASEADDRESS + queryString))
2070+
);
2071+
2072+
return oDataQueryOptions;
2073+
}
2074+
2075+
static HttpRequest BuildRequest(IServiceProvider serviceProvider, IEdmModel model, Uri uri)
2076+
{
2077+
var request = new DefaultHttpContext()
2078+
{
2079+
RequestServices = serviceProvider
2080+
}.Request;
2081+
2082+
var oDataOptions = new ODataOptions().AddRouteComponents("key", model,
2083+
x => x.AddSingleton<ISearchBinder, OpsTenantSearchBinder>());
2084+
var (_, routeProvider) = oDataOptions.RouteComponents["key"];
2085+
2086+
request.ODataFeature().Services = routeProvider;
2087+
2088+
request.Method = "GET";
2089+
request.Host = new HostString(uri.Host, uri.Port);
2090+
request.Path = uri.LocalPath;
2091+
request.QueryString = new QueryString(uri.Query);
2092+
2093+
return request;
2094+
}
2095+
2096+
static readonly string BASEADDRESS = "http://localhost:16324";
2097+
}
2098+
2099+
internal class TestMvcCoreBuilder : IMvcCoreBuilder
2100+
{
2101+
public ApplicationPartManager PartManager { get; set; }
2102+
public IServiceCollection Services { get; set; }
2103+
}
20192104
}

0 commit comments

Comments
 (0)