AutoMapper.AspNetCore.OData.EFCore
8.0.0
Prefix Reserved
dotnet add package AutoMapper.AspNetCore.OData.EFCore --version 8.0.0
NuGet\Install-Package AutoMapper.AspNetCore.OData.EFCore -Version 8.0.0
<PackageReference Include="AutoMapper.AspNetCore.OData.EFCore" Version="8.0.0" />
<PackageVersion Include="AutoMapper.AspNetCore.OData.EFCore" Version="8.0.0" />
<PackageReference Include="AutoMapper.AspNetCore.OData.EFCore" />
paket add AutoMapper.AspNetCore.OData.EFCore --version 8.0.0
#r "nuget: AutoMapper.AspNetCore.OData.EFCore, 8.0.0"
#:package AutoMapper.AspNetCore.OData.EFCore@8.0.0
#addin nuget:?package=AutoMapper.AspNetCore.OData.EFCore&version=8.0.0
#tool nuget:?package=AutoMapper.AspNetCore.OData.EFCore&version=8.0.0
AutoMapper.Extensions.OData
Creates LINQ expressions from ODataQueryOptions and executes the query.
NuGet Package Downloads
Usage
To use:
- Configure object maps with explicit expansion.
- Call the GetAsync or GetQueryAsync extension method from your OData controller. IMapper is an AutoMapper interface.
public class CoreBuildingMappings : AutoMapper.Profile
{
public CoreBuildingMappings()
{
CreateMap<TBuilding, CoreBuilding>()
.ForMember(d => d.Name, o => o.MapFrom(s => s.LongName))
.ForMember(d => d.Tenant, o => o.MapFrom(s => s.Mandator))
.ForAllMembers(o => o.ExplicitExpansion());
CreateMap<TBuilder, OpsBuilder>()
.ForAllMembers(o => o.ExplicitExpansion());
CreateMap<TCity, OpsCity>()
.ForAllMembers(o => o.ExplicitExpansion());
}
}
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<IQueryable<TModel>> GetQueryAsync<TModel, TData>(this IQueryable<TData> query, IMapper mapper, ODataQueryOptions<TModel> options, HandleNullPropagationOption handleNullPropagation = HandleNullPropagationOption.Default);
public class CoreBuildingController : ODataController
{
private readonly IMapper _mapper;
public CoreBuildingController(MyDbContext context, IMapper mapper)
{
Context = context;
_mapper = mapper;
}
MyDbContext Context { get; set; }
[HttpGet]
public async Task<IActionResult> Get(ODataQueryOptions<CoreBuilding> options)
{
return Ok(await Context.BuildingSet.GetQueryAsync(_mapper, options));
}
}
<br><br>
Do not use the EnableQuery Attribute
Using EnableQuery with AutoMapper.Extensions.OData will result in some operations being applied more than once e.g. in the tests,
if TMandator has a total of two records then without EnableQuery applied to the controller action, the OData query http://localhost:16324/opstenant?$skip=1&$top=1&$orderby=Name will return one record as expected. However with EnableQuery applied
no records will be returned because the skip operation has been applied twice.
<br><br>
OData query examples:
http://localhost:<port>/opstenant?$top=5&$expand=Buildings&$filter=Name eq 'One'&$orderby=Name desc
http://localhost:<port>/opstenant?$top=5&$expand=Buildings&$filter=Name ne 'One'&$orderby=Name desc
http://localhost:<port>/opstenant?$filter=Name eq 'One'
http://localhost:<port>/opstenant?$top=5&$expand=Buildings&$orderby=Name desc
http://localhost:<port>/opstenant?$orderby=Name desc
http://localhost:<port>/opstenant?$orderby=Name desc&$count=true
http://localhost:<port>/opstenant?$top=5&$filter=Name eq 'One'&$orderby=Name desc&$count=true
http://localhost:<port>/opstenant?$top=5&$select=Name, Identity
http://localhost:<port>/opstenant?$top=5&$expand=Buildings&$filter=Name ne 'One'&$orderby=Name desc
http://localhost:<port>/opstenant?$top=5&$expand=Buildings($expand=Builder($expand=City))&$filter=Name ne 'One'&$orderby=Name desc
http://localhost:<port>/opstenant?$top=5&$select=Buildings,Name&$expand=Buildings($select=Name,Builder;$expand=Builder($select=Name,City;$expand=City))&$filter=Name ne 'One'&$orderby=Name desc
http://localhost:<port>/corebuilding?$top=5&$expand=Builder,Tenant&$filter=name ne 'One L1'&$orderby=Name desc
http://localhost:<port>/corebuilding?$top=5&$expand=Builder($expand=City),Tenant&$filter=name ne 'One L2'&$orderby=Name desc
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- AutoMapper.Extensions.ExpressionMapping (>= 9.0.0 && < 10.0.0)
- LogicBuilder.Expressions.Utils (>= 7.0.0)
- Microsoft.AspNetCore.OData (>= 9.1.1)
- Microsoft.EntityFrameworkCore (>= 8.0.11)
-
net9.0
- AutoMapper.Extensions.ExpressionMapping (>= 9.0.0 && < 10.0.0)
- LogicBuilder.Expressions.Utils (>= 7.0.0)
- Microsoft.AspNetCore.OData (>= 9.1.1)
- Microsoft.EntityFrameworkCore (>= 9.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on AutoMapper.AspNetCore.OData.EFCore:
| Package | Downloads |
|---|---|
|
RESTworld.AspNetCore
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 8.0.0 | 5,497 | 7/12/2025 |
| 7.0.4 | 14,327 | 7/5/2025 |
| 7.0.2 | 43,646 | 5/10/2025 |
| 7.0.1 | 3,895 | 4/23/2025 |
| 7.0.0 | 58,277 | 2/15/2025 |
| 6.1.1 | 20,732 | 1/19/2025 |
| 6.1.0 | 7,519 | 1/3/2025 |
| 6.0.0 | 31,689 | 11/27/2024 |
| 5.0.2 | 1,161,204 | 7/27/2024 |
| 5.0.1 | 65,399 | 6/13/2024 |
| 5.0.0 | 753,314 | 2/19/2024 |
| 4.0.2 | 66,142 | 12/28/2023 |
| 4.0.1 | 169,086 | 8/19/2023 |
| 4.0.0 | 352,981 | 10/1/2022 |
| 3.0.6 | 23,155 | 10/1/2022 |
| 3.0.5 | 211,179 | 6/17/2022 |
| 3.0.4 | 23,443 | 4/15/2022 |
| 3.0.3 | 3,921 | 4/5/2022 |
| 3.0.2 | 3,514 | 2/26/2022 |
| 3.0.1 | 10,182 | 2/12/2022 |
| 3.0.0 | 6,699 | 1/31/2022 |
| 2.2.2 | 82,637 | 10/21/2021 |
| 2.2.1 | 54,739 | 8/9/2021 |
| 2.2.0-preview.1 | 2,451 | 4/10/2021 |
| 2.1.1 | 148,616 | 2/28/2021 |
| 2.1.1-preview.0 | 408 | 2/22/2021 |
| 2.1.0 | 41,720 | 11/27/2020 |
| 2.0.3-preview.2 | 430 | 11/12/2020 |
| 2.0.3-preview.1 | 442 | 11/9/2020 |
| 2.0.3-preview.0 | 1,086 | 11/2/2020 |
| 2.0.2 | 48,432 | 10/26/2020 |
| 2.0.2-preview.1 | 421 | 10/22/2020 |
| 2.0.2-preview.0 | 1,391 | 9/16/2020 |
| 2.0.1 | 3,436 | 9/8/2020 |
| 2.0.1-preview.1.2 | 421 | 9/8/2020 |
| 2.0.1-preview.1 | 414 | 9/4/2020 |
| 2.0.1-preview.0 | 622 | 8/26/2020 |
| 2.0.0 | 205,291 | 7/8/2020 |
| 1.0.5 | 21,862 | 5/25/2020 |
| 1.0.4-preview03 | 653 | 5/17/2020 |
| 1.0.3 | 1,662 | 5/3/2020 |
| 1.0.2-preview04 | 618 | 4/29/2020 |
| 1.0.1 | 3,827 | 2/9/2020 |
| 1.0.1-preview02 | 700 | 2/5/2020 |
| 1.0.1-preview01 | 608 | 2/4/2020 |
| 1.0.0 | 33,321 | 9/11/2019 |
| 1.0.0-preview07 | 631 | 9/9/2019 |
Supporting AutoMapper v15 (EF Core only).