Skip to content

Commit 59825ac

Browse files
authored
Supporting AutoMapper v16 and Microsoft.AspNetCore.OData v9.4.1 (#248)
1 parent 1674579 commit 59825ac

File tree

15 files changed

+128
-146
lines changed

15 files changed

+128
-146
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Setup .NET Core
2020
uses: actions/setup-dotnet@v1
2121
with:
22-
dotnet-version: 9.x
22+
dotnet-version: 10.x
2323

2424
- name: Set Variables
2525
run: |

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Setup .NET Core
1818
uses: actions/setup-dotnet@v1
1919
with:
20-
dotnet-version: 9.x
20+
dotnet-version: 10.x
2121

2222
- name: Set Variables
2323
run: |

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
4+
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
55
<RootNamespace>AutoMapper.AspNet.OData</RootNamespace>
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 v15 (EF Core only).</PackageReleaseNotes>
9+
<PackageReleaseNotes>Supporting AutoMapper v16 (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>
@@ -62,7 +62,7 @@
6262
<PackageReference Include="AutoMapper.Extensions.ExpressionMapping" Version="[6.0.4,7.0.0)" />
6363
<PackageReference Include="EntityFramework" Version="6.5.1" />
6464
<PackageReference Include="LogicBuilder.Expressions.Utils" Version="7.0.0" />
65-
<PackageReference Include="Microsoft.AspNetCore.OData" Version="9.1.1" />
65+
<PackageReference Include="Microsoft.AspNetCore.OData" Version="9.4.1" />
6666
<PackageReference Include="MinVer" Version="6.0.0">
6767
<PrivateAssets>all</PrivateAssets>
6868
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
4+
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
55
<RootNamespace>AutoMapper.AspNet.OData</RootNamespace>
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 v15 (EF Core only).</PackageReleaseNotes>
9+
<PackageReleaseNotes>Supporting AutoMapper v16 (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,9 +30,9 @@
3030
</ItemGroup>
3131

3232
<ItemGroup>
33-
<PackageReference Include="AutoMapper.Extensions.ExpressionMapping" Version="[9.0.0,10.0.0)" />
33+
<PackageReference Include="AutoMapper.Extensions.ExpressionMapping" Version="[10.0.0,11.0.0)" />
3434
<PackageReference Include="LogicBuilder.Expressions.Utils" Version="7.0.0" />
35-
<PackageReference Include="Microsoft.AspNetCore.OData" Version="9.1.1" />
35+
<PackageReference Include="Microsoft.AspNetCore.OData" Version="9.4.1" />
3636
<PackageReference Include="MinVer" Version="6.0.0">
3737
<PrivateAssets>all</PrivateAssets>
3838
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
@@ -47,6 +47,10 @@
4747
<ItemGroup Condition=" '$(TargetFramework)' == 'net9.0' ">
4848
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.0" />
4949
</ItemGroup>
50+
51+
<ItemGroup Condition=" '$(TargetFramework)' == 'net10.0' ">
52+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.0" />
53+
</ItemGroup>
5054

5155
<ItemGroup>
5256
<FrameworkReference Include="Microsoft.AspNetCore.App" />

AutoMapper.AspNetCore.OData.EFCore/FilterHelper.cs

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,13 @@ private IExpressionPart GetIsOdFilterPart(List<QueryNode> arguments)
241241
if (!(arguments[0] is SingleValueNode sourceNode))
242242
throw new ArgumentException("Expected SingleValueNode for source node.");
243243

244-
if (!(arguments[1] is ConstantNode typeNode))
245-
throw new ArgumentException("Expected ConstantNode for type node.");
244+
if (arguments[1] is ConstantNode typeNode)
245+
return IsOf(GetCastType(typeNode));
246246

247-
return IsOf(GetCastType(typeNode));
247+
if (arguments[1] is SingleResourceCastNode singleResourceCastNode)
248+
return IsOf(GetCastType(singleResourceCastNode));
249+
250+
throw new ArgumentException("Expected ConstantNode or SingleResourceCastNode for type node.");
248251

249252
IExpressionPart IsOf(Type conversionType)
250253
=> new IsOfOperator(GetFilterPart(sourceNode), conversionType);
@@ -255,14 +258,25 @@ private IExpressionPart GetCastResourceFilterPart(List<QueryNode> arguments)
255258
if (!(arguments[0] is SingleValueNode sourceNode))
256259
throw new ArgumentException("Expected SingleValueNode for source node.");
257260

258-
if (!(arguments[1] is ConstantNode typeNode))
259-
throw new ArgumentException("Expected ConstantNode for type node.");
261+
if (arguments[1] is ConstantNode typeNode)
262+
{
263+
return Convert
264+
(
265+
GetClrType(sourceNode.TypeReference),
266+
GetCastType(typeNode)
267+
);
268+
}
260269

261-
return Convert
262-
(
263-
GetClrType(sourceNode.TypeReference),
264-
GetCastType(typeNode)
265-
);
270+
if (arguments[1] is SingleResourceCastNode singleResourceCastNode)
271+
{
272+
return Convert
273+
(
274+
GetClrType(sourceNode.TypeReference),
275+
GetCastType(singleResourceCastNode)
276+
);
277+
}
278+
279+
throw new ArgumentException("Expected ConstantNode or SingleResourceCastNode for type node.");
266280

267281
IExpressionPart Convert(Type operandType, Type conversionType)
268282
{
@@ -291,23 +305,36 @@ private IExpressionPart GetCastFilterPart(List<QueryNode> arguments)
291305
if (!(arguments[0] is SingleValueNode sourceNode))
292306
throw new ArgumentException("Expected SingleValueNode for source node.");
293307

294-
if (!(arguments[1] is ConstantNode typeNode))
295-
throw new ArgumentException("Expected ConstantNode for type node.");
308+
if (arguments[1] is ConstantNode typeNode)
309+
{
310+
return Convert
311+
(
312+
GetClrType(sourceNode.TypeReference),
313+
GetCastType(typeNode),
314+
typeNode.TypeReference
315+
);
316+
}
296317

297-
return Convert
298-
(
299-
GetClrType(sourceNode.TypeReference),
300-
GetCastType(typeNode)
301-
);
318+
if (arguments[1] is SingleResourceCastNode singleResourceCastNode)
319+
{
320+
return Convert
321+
(
322+
GetClrType(sourceNode.TypeReference),
323+
GetCastType(singleResourceCastNode),
324+
singleResourceCastNode.TypeReference
325+
);
326+
}
302327

303-
IExpressionPart Convert(Type operandType, Type conversionType)
328+
throw new ArgumentException("Expected ConstantNode or SingleResourceCastNode for type node.");
329+
330+
IExpressionPart Convert(Type operandType, Type conversionType, IEdmTypeReference edmTypeReference)
304331
{
305332
if (OperandIsNullConstant(sourceNode) || operandType == conversionType)
306333
return GetFilterPart(sourceNode);
307334

308335
if (ShouldConvertTypes(operandType, conversionType, sourceNode))
309336
{
310-
if ((!typeNode.TypeReference.IsPrimitive() && !typeNode.TypeReference.IsEnum())
337+
if ((!edmTypeReference.IsPrimitive() && !edmTypeReference.IsEnum())
311338
|| (!operandType.IsLiteralType() && !operandType.ToNullableUnderlyingType().IsEnum))
312339
return new ConstantOperator(null);
313340

@@ -345,6 +372,9 @@ IExpressionPart Convert(Type operandType, Type conversionType)
345372
private Type GetCastType(ConstantNode constantNode)
346373
=> TypeExtensions.GetClrType((string)constantNode.Value, false, typesCache);
347374

375+
private Type GetCastType(SingleResourceCastNode singleResourceCastNode)
376+
=> TypeExtensions.GetClrType(singleResourceCastNode.TypeReference, typesCache);
377+
348378
private IExpressionPart GetCustomMehodFilterPart(string functionName, SingleValueNode[] arguments)
349379
{
350380
MethodInfo methodInfo = CustomMethodCache.GetCachedCustomMethod(functionName, arguments.Select(p => GetClrType(p.TypeReference)));

AutoMapper.Extensions.OData.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 17
4-
VisualStudioVersion = 17.0.32112.339
3+
# Visual Studio Version 18
4+
VisualStudioVersion = 18.1.11312.151 d18.0
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoMapper.AspNetCore.OData.EFCore", "AutoMapper.AspNetCore.OData.EFCore\AutoMapper.AspNetCore.OData.EFCore.csproj", "{8E4C661E-C58A-4515-9CBF-F58D9D6E941D}"
77
EndProject

AutoMapper.OData.EF6.Tests/AutoMapper.OData.EF6.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net9.0</TargetFramework>
4+
<TargetFrameworks>net10.0</TargetFrameworks>
55

66
<IsPackable>false</IsPackable>
77
</PropertyGroup>

AutoMapper.OData.EFCore.Tests/AutoMapper.OData.EFCore.Tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net9.0</TargetFramework>
4+
<TargetFrameworks>net10.0</TargetFrameworks>
55

66
<IsPackable>false</IsPackable>
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.0" />
10+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="10.0.0" />
1111
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
1212
<PackageReference Include="xunit" Version="2.9.2" />
1313
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">

DAL.EFCore/DAL.EFCore.csproj

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
4+
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
55
</PropertyGroup>
66

7-
<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
8-
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" />
9-
</ItemGroup>
10-
11-
<ItemGroup Condition=" '$(TargetFramework)' == 'net7.0' ">
12-
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.0" />
13-
</ItemGroup>
14-
157
<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
168
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.11" />
179
</ItemGroup>
@@ -20,4 +12,8 @@
2012
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.0" />
2113
</ItemGroup>
2214

15+
<ItemGroup Condition=" '$(TargetFramework)' == 'net10.0' ">
16+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.0" />
17+
</ItemGroup>
18+
2319
</Project>

ExpressionBuilder.Tests/ExpressionBuilder.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net9.0</TargetFramework>
4+
<TargetFrameworks>net10.0</TargetFrameworks>
55

66
<IsPackable>false</IsPackable>
77
</PropertyGroup>

0 commit comments

Comments
 (0)