Skip to content

Commit

Permalink
Merge pull request #80 from AutoMapper/2Dot1
Browse files Browse the repository at this point in the history
Refactoring QuerySettings.
  • Loading branch information
BlaiseD authored Nov 27, 2020
2 parents f3a7303 + 3ba7385 commit 6cc9ed1
Show file tree
Hide file tree
Showing 21 changed files with 61 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<Compile Include="..\AutoMapper.AspNetCore.OData.EFCore\EdmTypeStructure.cs" Link="EdmTypeStructure.cs" />
<Compile Include="..\AutoMapper.AspNetCore.OData.EFCore\FilterHelper.cs" Link="FilterHelper.cs" />
<Compile Include="..\AutoMapper.AspNetCore.OData.EFCore\LinqExtensions.cs" Link="LinqExtensions.cs" />
<Compile Include="..\AutoMapper.AspNetCore.OData.EFCore\ODataSettings.cs" Link="ODataSettings.cs" />
<Compile Include="..\AutoMapper.AspNetCore.OData.EFCore\ProjectionSettings.cs" Link="ProjectionSettings.cs" />
<Compile Include="..\AutoMapper.AspNetCore.OData.EFCore\Properties\Resources.Designer.cs" Link="Properties\Resources.Designer.cs" />
<Compile Include="..\AutoMapper.AspNetCore.OData.EFCore\QuerySettings.cs" Link="QuerySettings.cs" />
Expand All @@ -40,7 +41,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="AutoMapper.Extensions.ExpressionMapping" Version="[4.0.2,5.0.0)" />
<PackageReference Include="AutoMapper.Extensions.ExpressionMapping" Version="[4.1.0,5.0.0)" />
<PackageReference Include="EntityFramework" Version="6.2.0" />
<PackageReference Include="LogicBuilder.Expressions.Utils" Version="4.0.2" />
<PackageReference Include="Microsoft.AspNet.OData" Version="7.4.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<Compile Include="..\AutoMapper.AspNetCore.OData.EFCore\FilterHelper.cs" Link="FilterHelper.cs" />
<Compile Include="..\AutoMapper.AspNetCore.OData.EFCore\LinqExtensions.cs" Link="LinqExtensions.cs" />
<Compile Include="..\AutoMapper.AspNetCore.OData.EFCore\ODataQueryOptionsExtensions.cs" Link="ODataQueryOptionsExtensions.cs" />
<Compile Include="..\AutoMapper.AspNetCore.OData.EFCore\ODataSettings.cs" Link="ODataSettings.cs" />
<Compile Include="..\AutoMapper.AspNetCore.OData.EFCore\ProjectionSettings.cs" Link="ProjectionSettings.cs" />
<Compile Include="..\AutoMapper.AspNetCore.OData.EFCore\Properties\Resources.Designer.cs" Link="Properties\Resources.Designer.cs" />
<Compile Include="..\AutoMapper.AspNetCore.OData.EFCore\QuerySettings.cs" Link="QuerySettings.cs" />
Expand All @@ -40,7 +41,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="AutoMapper.Extensions.ExpressionMapping" Version="[4.0.2,5.0.0)" />
<PackageReference Include="AutoMapper.Extensions.ExpressionMapping" Version="[4.1.0,5.0.0)" />
<PackageReference Include="EntityFramework" Version="6.3.0" />
<PackageReference Include="LogicBuilder.Expressions.Utils" Version="4.0.2" />
<PackageReference Include="Microsoft.AspNetCore.OData" Version="7.4.1" />
Expand Down
8 changes: 4 additions & 4 deletions AutoMapper.AspNetCore.OData.EF6/QueryableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static ICollection<TModel> Get<TModel, TData>(this IQueryable<TData> quer
/// <returns></returns>
public static ICollection<TModel> Get<TModel, TData>(this IQueryable<TData> query, IMapper mapper, ODataQueryOptions<TModel> options, QuerySettings querySettings)
where TModel : class
=> query.Get(mapper, options, querySettings == null ? HandleNullPropagationOption.Default : querySettings.HandleNullPropagation);
=> query.Get(mapper, options, querySettings?.ODataSettings?.HandleNullPropagation ?? HandleNullPropagationOption.Default);


/// <summary>
Expand Down Expand Up @@ -71,7 +71,7 @@ public static async Task<ICollection<TModel>> GetAsync<TModel, TData>(this IQuer

public static async Task<ICollection<TModel>> GetAsync<TModel, TData>(this IQueryable<TData> query, IMapper mapper, ODataQueryOptions<TModel> options, QuerySettings querySettings = null)
where TModel : class
=> await query.GetAsync(mapper, options, querySettings == null ? HandleNullPropagationOption.Default : querySettings.HandleNullPropagation);
=> await query.GetAsync(mapper, options, querySettings?.ODataSettings?.HandleNullPropagation ?? HandleNullPropagationOption.Default);

/// <summary>
/// GetQueryAsync
Expand All @@ -85,7 +85,7 @@ public static async Task<ICollection<TModel>> GetAsync<TModel, TData>(this IQuer
/// <returns></returns>
public static async Task<IQueryable<TModel>> GetQueryAsync<TModel, TData>(this IQueryable<TData> query, IMapper mapper, ODataQueryOptions<TModel> options, HandleNullPropagationOption handleNullPropagation = HandleNullPropagationOption.Default)
where TModel : class
=> await query.GetQueryAsync(mapper, options, new QuerySettings { HandleNullPropagation = handleNullPropagation });
=> await query.GetQueryAsync(mapper, options, new QuerySettings { ODataSettings = new ODataSettings { HandleNullPropagation = handleNullPropagation } });

/// <summary>
/// GetQueryAsync
Expand All @@ -107,7 +107,7 @@ public static async Task<IQueryable<TModel>> GetQueryAsync<TModel, TData>(this I
)
.ToList();

Expression<Func<TModel, bool>> filter = options.Filter.ToFilterExpression<TModel>(querySettings == null ? HandleNullPropagationOption.Default : querySettings.HandleNullPropagation);
Expression<Func<TModel, bool>> filter = options.Filter.ToFilterExpression<TModel>(querySettings?.ODataSettings?.HandleNullPropagation ?? HandleNullPropagationOption.Default);
Expression<Func<IQueryable<TModel>, IQueryable<TModel>>> queryableExpression = options.GetQueryableExpression();
Expression<Func<IQueryable<TModel>, long>> countExpression = LinqExtensions.GetCountExpression<TModel>(filter);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AutoMapper.Extensions.ExpressionMapping" Version="[4.0.2,5.0.0)" />
<PackageReference Include="AutoMapper.Extensions.ExpressionMapping" Version="[4.1.0,5.0.0)" />
<PackageReference Include="LogicBuilder.Expressions.Utils" Version="4.0.2" />
<PackageReference Include="Microsoft.AspNetCore.OData" Version="7.4.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.0" />
Expand Down
19 changes: 19 additions & 0 deletions AutoMapper.AspNetCore.OData.EFCore/ODataSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Microsoft.AspNet.OData.Query;

namespace AutoMapper.AspNet.OData
{
/// <summary>
/// Settings for configuring OData options on the server
/// </summary>
public class ODataSettings
{
/// <summary>
/// Gets or sets a value indicating how null propagation should
/// be handled during query composition.
/// </summary>
/// <value>
/// The default is <see cref="F:Microsoft.AspNet.OData.Query.HandleNullPropagationOption.Default" />.
/// </value>
public HandleNullPropagationOption HandleNullPropagation { get; set; } = HandleNullPropagationOption.Default;
}
}
8 changes: 2 additions & 6 deletions AutoMapper.AspNetCore.OData.EFCore/QuerySettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@ namespace AutoMapper.AspNet.OData
public class QuerySettings
{
/// <summary>
/// Gets or sets a value indicating how null propagation should
/// be handled during query composition.
/// Settings for configuring OData options on the server
/// </summary>
/// <value>
/// The default is <see cref="F:Microsoft.AspNet.OData.Query.HandleNullPropagationOption.Default" />.
/// </value>
public HandleNullPropagationOption HandleNullPropagation { get; set; } = HandleNullPropagationOption.Default;
public ODataSettings ODataSettings { get; set; }

/// <summary>
/// Miscellaneous arguments for IMapper.ProjectTo
Expand Down
14 changes: 7 additions & 7 deletions AutoMapper.AspNetCore.OData.EFCore/QueryableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ namespace AutoMapper.AspNet.OData
{
public static class QueryableExtensions
{
public static ICollection<TModel> Get<TModel, TData>(this IQueryable<TData> query, IMapper mapper, ODataQueryOptions<TModel> options, HandleNullPropagationOption handleNullPropagation = HandleNullPropagationOption.Default)
public static ICollection<TModel> Get<TModel, TData>(this IQueryable<TData> query, IMapper mapper, ODataQueryOptions<TModel> options, HandleNullPropagationOption handleNullPropagation = HandleNullPropagationOption.False)
where TModel : class
=> Task.Run(async () => await query.GetAsync(mapper, options, handleNullPropagation)).Result;

public static ICollection<TModel> Get<TModel, TData>(this IQueryable<TData> query, IMapper mapper, ODataQueryOptions<TModel> options, QuerySettings querySettings = null)
where TModel : class
=> query.Get(mapper, options, querySettings == null ? HandleNullPropagationOption.Default : querySettings.HandleNullPropagation);
=> query.Get(mapper, options, querySettings?.ODataSettings?.HandleNullPropagation ?? HandleNullPropagationOption.False);

public static async Task<ICollection<TModel>> GetAsync<TModel, TData>(this IQueryable<TData> query, IMapper mapper, ODataQueryOptions<TModel> options, HandleNullPropagationOption handleNullPropagation = HandleNullPropagationOption.Default)
public static async Task<ICollection<TModel>> GetAsync<TModel, TData>(this IQueryable<TData> query, IMapper mapper, ODataQueryOptions<TModel> options, HandleNullPropagationOption handleNullPropagation = HandleNullPropagationOption.False)
where TModel : class
{
ICollection<Expression<Func<IQueryable<TModel>, IIncludableQueryable<TModel, object>>>> includeExpressions = options.SelectExpand.GetIncludes().BuildIncludesExpressionCollection<TModel>()?.ToList();
Expand All @@ -39,11 +39,11 @@ public static async Task<ICollection<TModel>> GetAsync<TModel, TData>(this IQuer

public static async Task<ICollection<TModel>> GetAsync<TModel, TData>(this IQueryable<TData> query, IMapper mapper, ODataQueryOptions<TModel> options, QuerySettings querySettings = null)
where TModel : class
=> await query.GetAsync(mapper, options, querySettings == null ? HandleNullPropagationOption.Default : querySettings.HandleNullPropagation);
=> await query.GetAsync(mapper, options, querySettings?.ODataSettings?.HandleNullPropagation ?? HandleNullPropagationOption.False);

public static async Task<IQueryable<TModel>> GetQueryAsync<TModel, TData>(this IQueryable<TData> query, IMapper mapper, ODataQueryOptions<TModel> options, HandleNullPropagationOption handleNullPropagation = HandleNullPropagationOption.Default)
public static async Task<IQueryable<TModel>> GetQueryAsync<TModel, TData>(this IQueryable<TData> query, IMapper mapper, ODataQueryOptions<TModel> options, HandleNullPropagationOption handleNullPropagation = HandleNullPropagationOption.False)
where TModel : class
=> await query.GetQueryAsync(mapper, options, new QuerySettings { HandleNullPropagation = handleNullPropagation });
=> await query.GetQueryAsync(mapper, options, new QuerySettings { ODataSettings = new ODataSettings { HandleNullPropagation = handleNullPropagation } });

public static async Task<IQueryable<TModel>> GetQueryAsync<TModel, TData>(this IQueryable<TData> query, IMapper mapper, ODataQueryOptions<TModel> options, QuerySettings querySettings = null)
where TModel : class
Expand All @@ -55,7 +55,7 @@ public static async Task<IQueryable<TModel>> GetQueryAsync<TModel, TData>(this I
)
.ToList();

Expression<Func<TModel, bool>> filter = options.Filter.ToFilterExpression<TModel>(querySettings == null ? HandleNullPropagationOption.False : querySettings.HandleNullPropagation);
Expression<Func<TModel, bool>> filter = options.Filter.ToFilterExpression<TModel>(querySettings?.ODataSettings?.HandleNullPropagation ?? HandleNullPropagationOption.False);
Expression<Func<IQueryable<TModel>, IQueryable<TModel>>> queryableExpression = options.GetQueryableExpression();
Expression<Func<IQueryable<TModel>, long>> countExpression = LinqExtensions.GetCountExpression<TModel>(filter);

Expand Down
6 changes: 3 additions & 3 deletions AutoMapper.Extensions.OData.sln
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MigrationTool", "MigrationT
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SeedDatabase", "SeedDatabase\SeedDatabase.csproj", "{CE492720-2000-4533-93AF-5AA71A65D305}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoMapper.OData.EF6.Tests", "AutoMapper.OData.EF6.Tests\AutoMapper.OData.EF6.Tests.csproj", "{BF11CF7F-0424-46F7-A60E-B614525C68C7}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoMapper.OData.EF6.Tests", "AutoMapper.OData.EF6.Tests\AutoMapper.OData.EF6.Tests.csproj", "{BF11CF7F-0424-46F7-A60E-B614525C68C7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebAPI.OData.EF6", "WebAPI.OData.EF6\WebAPI.OData.EF6.csproj", "{4C069416-CF7B-45C7-8C8F-B3D24DC16D01}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebAPI.OData.EF6", "WebAPI.OData.EF6\WebAPI.OData.EF6.csproj", "{4C069416-CF7B-45C7-8C8F-B3D24DC16D01}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DAL.EF6", "DAL.EF6\DAL.EF6.csproj", "{8139DB48-8A96-405A-9B02-44C4AEF79FD0}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DAL.EF6", "DAL.EF6\DAL.EF6.csproj", "{8139DB48-8A96-405A-9B02-44C4AEF79FD0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
2 changes: 1 addition & 1 deletion AutoMapper.OData.EF6.Tests/GetQuerySelectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ async Task<IQueryable<TModel>> DoGet(IMapper mapper, TestDbContext context)
serviceProvider,
serviceProvider.GetRequiredService<IRouteBuilder>()
),
new QuerySettings { HandleNullPropagation = HandleNullPropagationOption.False }
new QuerySettings { ODataSettings = new ODataSettings { HandleNullPropagation = HandleNullPropagationOption.False } }
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion AutoMapper.OData.EF6.Tests/GetQueryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ await Get<CoreBuilding, TBuilding>
new QuerySettings
{
ProjectionSettings = new ProjectionSettings { Parameters = parameters },
HandleNullPropagation = HandleNullPropagationOption.False
ODataSettings = new ODataSettings { HandleNullPropagation = HandleNullPropagationOption.False }
}
)
);
Expand Down
2 changes: 1 addition & 1 deletion AutoMapper.OData.EF6.Tests/GetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ async Task<ICollection<TModel>> DoGet(IMapper mapper, TestDbContext context)
serviceProvider,
serviceProvider.GetRequiredService<IRouteBuilder>()
),
new QuerySettings { HandleNullPropagation = HandleNullPropagationOption.False }
new QuerySettings { ODataSettings = new ODataSettings { HandleNullPropagation = HandleNullPropagationOption.False } }
);
}
}
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 @@ -149,7 +149,7 @@ async Task<IQueryable<TModel>> DoGet(IMapper mapper, MyDbContext context)
serviceProvider,
serviceProvider.GetRequiredService<IRouteBuilder>()
),
new QuerySettings { HandleNullPropagation = HandleNullPropagationOption.False }
new QuerySettings { ODataSettings = new ODataSettings { HandleNullPropagation = HandleNullPropagationOption.False } }
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion AutoMapper.OData.EFCore.Tests/GetQueryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ await Get<CoreBuilding, TBuilding>
new QuerySettings
{
ProjectionSettings = new ProjectionSettings { Parameters = parameters },
HandleNullPropagation = HandleNullPropagationOption.False
ODataSettings = new ODataSettings { HandleNullPropagation = HandleNullPropagationOption.False }
}
)
);
Expand Down
2 changes: 1 addition & 1 deletion AutoMapper.OData.EFCore.Tests/GetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ async Task<ICollection<TModel>> DoGet(IMapper mapper, MyDbContext context)
serviceProvider,
serviceProvider.GetRequiredService<IRouteBuilder>()
),
new QuerySettings{HandleNullPropagation = HandleNullPropagationOption.False}
new QuerySettings{ ODataSettings = new ODataSettings { HandleNullPropagation = HandleNullPropagationOption.False } }
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions WebAPI.AspNet.OData.EF6/Controllers/OpsTenantController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public CoreBuildingController(IMapper mapper)
[HttpGet]
public async Task<IHttpActionResult> Get(ODataQueryOptions<CoreBuilding> options)
{
return Ok(await Repository.BuildingSet.GetQueryAsync(this._mapper, options, new QuerySettings { HandleNullPropagation = HandleNullPropagationOption.Default }));
return Ok(await Repository.BuildingSet.GetQueryAsync(this._mapper, options, new QuerySettings { ODataSettings = new ODataSettings { HandleNullPropagation = HandleNullPropagationOption.Default } }));
}
}

Expand All @@ -47,7 +47,7 @@ public OpsTenantController(IMapper mapper)
[HttpGet]
public async Task<IHttpActionResult> Get(ODataQueryOptions<OpsTenant> options)
{
return Ok(await Repository.MandatorSet.GetQueryAsync(this._mapper, options, new QuerySettings { HandleNullPropagation = HandleNullPropagationOption.Default }));
return Ok(await Repository.MandatorSet.GetQueryAsync(this._mapper, options, new QuerySettings { ODataSettings = new ODataSettings { HandleNullPropagation = HandleNullPropagationOption.Default } }));
}
}
}
6 changes: 3 additions & 3 deletions WebAPI.AspNet.OData.EF6/WebAPI.AspNet.OData.EF6.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="AutoMapper, Version=10.0.0.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
<HintPath>..\packages\AutoMapper.10.0.0\lib\net461\AutoMapper.dll</HintPath>
<HintPath>..\packages\AutoMapper.10.1.1\lib\net461\AutoMapper.dll</HintPath>
</Reference>
<Reference Include="AutoMapper.AspNet.OData.EF6, Version=2.0.0.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
<HintPath>..\packages\AutoMapper.AspNet.OData.EF6.2.0.3-preview.2\lib\net461\AutoMapper.AspNet.OData.EF6.dll</HintPath>
<HintPath>..\packages\AutoMapper.AspNet.OData.EF6.2.0.3-preview.2.2\lib\net461\AutoMapper.AspNet.OData.EF6.dll</HintPath>
</Reference>
<Reference Include="AutoMapper.Extensions.ExpressionMapping, Version=4.0.0.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
<HintPath>..\packages\AutoMapper.Extensions.ExpressionMapping.4.0.2\lib\net461\AutoMapper.Extensions.ExpressionMapping.dll</HintPath>
<HintPath>..\packages\AutoMapper.Extensions.ExpressionMapping.4.1.0\lib\net461\AutoMapper.Extensions.ExpressionMapping.dll</HintPath>
</Reference>
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll</HintPath>
Expand Down
6 changes: 3 additions & 3 deletions WebAPI.AspNet.OData.EF6/packages.config
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AutoMapper" version="10.0.0" targetFramework="net472" />
<package id="AutoMapper.AspNet.OData.EF6" version="2.0.3-preview.2" targetFramework="net472" />
<package id="AutoMapper.Extensions.ExpressionMapping" version="4.0.2" targetFramework="net472" />
<package id="AutoMapper" version="10.1.1" targetFramework="net472" />
<package id="AutoMapper.AspNet.OData.EF6" version="2.0.3-preview.2.2" targetFramework="net472" />
<package id="AutoMapper.Extensions.ExpressionMapping" version="4.1.0" targetFramework="net472" />
<package id="EntityFramework" version="6.2.0" targetFramework="net472" />
<package id="LogicBuilder.Expressions.Utils" version="4.0.2" targetFramework="net472" />
<package id="LogicBuilder.Structures" version="4.0.2" targetFramework="net472" />
Expand Down
Loading

0 comments on commit 6cc9ed1

Please sign in to comment.