automapperdev - AutoMapper.AspNetCore.OData.EF6 8.0.1-alpha.0.1

Creates LINQ expressions from ODataQueryOptions and executes the query.

PM> Install-Package AutoMapper.AspNetCore.OData.EF6 -Version 8.0.1-alpha.0.1 -Source https://www.myget.org/F/automapperdev/api/v3/index.json

Copy to clipboard

> nuget.exe install AutoMapper.AspNetCore.OData.EF6 -Version 8.0.1-alpha.0.1 -Source https://www.myget.org/F/automapperdev/api/v3/index.json

Copy to clipboard

> dotnet add package AutoMapper.AspNetCore.OData.EF6 --version 8.0.1-alpha.0.1 --source https://www.myget.org/F/automapperdev/api/v3/index.json

Copy to clipboard
<PackageReference Include="AutoMapper.AspNetCore.OData.EF6" Version="8.0.1-alpha.0.1" />
Copy to clipboard
source https://www.myget.org/F/automapperdev/api/v3/index.json

nuget AutoMapper.AspNetCore.OData.EF6  ~> 8.0.1-alpha.0.1
Copy to clipboard

> choco install AutoMapper.AspNetCore.OData.EF6 --version 8.0.1-alpha.0.1 --source https://www.myget.org/F/automapperdev/api/v2

Copy to clipboard
Import-Module PowerShellGet
Register-PSRepository -Name "automapperdev" -SourceLocation "https://www.myget.org/F/automapperdev/api/v2"
Install-Module -Name "AutoMapper.AspNetCore.OData.EF6" -RequiredVersion "8.0.1-alpha.0.1" -Repository "automapperdev" -AllowPreRelease
Copy to clipboard

Browse the sources in this package using Visual Studio or WinDbg by configuring the following symbol server URL: https://www.myget.org/F/automapperdev/api/v2/symbolpackage/


AutoMapper.Extensions.OData

Creates LINQ expressions from ODataQueryOptions and executes the query.

NuGet Package Downloads

NuGet
NuGet
NuGet

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));
        }
    }



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.



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

Supporting AutoMapper v15 (EF Core only).

  • .NETFramework 8.0
    • AutoMapper.Extensions.ExpressionMapping (>= 6.0.4 && < 7.0.0)
    • EntityFramework (>= 6.5.1)
    • LogicBuilder.Expressions.Utils (>= 7.0.0)
    • Microsoft.AspNetCore.OData (>= 9.1.1)
    • System.Data.SqlClient (>= 4.9.0)
    • System.Drawing.Common (>= 9.0.0)
  • .NETFramework 9.0
    • AutoMapper.Extensions.ExpressionMapping (>= 6.0.4 && < 7.0.0)
    • EntityFramework (>= 6.5.1)
    • LogicBuilder.Expressions.Utils (>= 7.0.0)
    • Microsoft.AspNetCore.OData (>= 9.1.1)
    • System.Data.SqlClient (>= 4.9.0)
    • System.Drawing.Common (>= 9.0.0)
  • .NETFramework 8.0: 8.0.0.0
  • .NETFramework 9.0: 9.0.0.0

Owners

Jimmy Bogard

Authors

BlaiseD

Project URL

https://github.com/AutoMapper/AutoMapper.Extensions.OData

License

Unknown

Tags

linq expressions odata efcore

Info

87 total downloads
0 downloads for version 8.0.1-alpha.0.1
Download (74.96 KB)
Download symbols (44.35 KB)
Found on the current feed only

Package history

Version Size Last updated Downloads Mirrored?
8.0.1-alpha.0.1 74.96 KB Fri, 21 Nov 2025 18:16:16 GMT 0
7.0.5-alpha.0.1 74.88 KB Sat, 12 Jul 2025 15:11:56 GMT 0
7.0.3-alpha.0.1 74.87 KB Sat, 31 May 2025 14:35:25 GMT 0
7.0.2-alpha.0.1 74.53 KB Fri, 09 May 2025 10:37:14 GMT 0
7.0.1-alpha.0.1 74.07 KB Sat, 19 Apr 2025 13:52:26 GMT 2
6.1.2-alpha.0.3 74.07 KB Sat, 15 Feb 2025 16:35:56 GMT 0
6.1.2-alpha.0.2 74.05 KB Sat, 15 Feb 2025 16:21:13 GMT 0
6.1.2-alpha.0.1 74.05 KB Mon, 20 Jan 2025 19:29:38 GMT 0
6.1.1-alpha.0.1 74.02 KB Sun, 05 Jan 2025 14:05:03 GMT 0
6.0.1-alpha.0.4 74.2 KB Fri, 03 Jan 2025 18:06:42 GMT 0
6.0.1-alpha.0.3 67.97 KB Mon, 16 Dec 2024 11:10:04 GMT 0
6.0.1-alpha.0.2 67.98 KB Sun, 15 Dec 2024 16:41:52 GMT 0
6.0.1-alpha.0.1 67.72 KB Sat, 07 Dec 2024 14:49:02 GMT 0
5.0.3-alpha.0.2 67.07 KB Mon, 25 Nov 2024 12:05:07 GMT 0
5.0.3-alpha.0.1 98.58 KB Thu, 14 Nov 2024 11:27:59 GMT 0
5.0.2-alpha.0.1 96.5 KB Sat, 06 Jul 2024 13:20:01 GMT 0
5.0.1-alpha.0.2 96.37 KB Wed, 12 Jun 2024 10:16:03 GMT 0
5.0.1-alpha.0.1 96.36 KB Wed, 12 Jun 2024 10:10:59 GMT 0
4.0.3-alpha.0.1 95.95 KB Mon, 19 Feb 2024 14:25:48 GMT 1
4.0.2-alpha.0.1 94.84 KB Thu, 28 Dec 2023 12:41:26 GMT 0
4.0.1-alpha.0.6 64.9 KB Sat, 19 Aug 2023 12:33:37 GMT 2
4.0.1-alpha.0.5 64.91 KB Fri, 18 Aug 2023 17:14:57 GMT 1
4.0.1-alpha.0.4 94.59 KB Tue, 17 Jan 2023 21:18:24 GMT 1
4.0.1-alpha.0.3 94.57 KB Mon, 16 Jan 2023 21:28:35 GMT 1
4.0.1-alpha.0.2 94.28 KB Fri, 11 Nov 2022 17:04:17 GMT 1
4.0.1-alpha.0.1 94.27 KB Fri, 11 Nov 2022 16:12:58 GMT 1
3.0.7-alpha.0.1 94.29 KB Sat, 01 Oct 2022 12:13:29 GMT 1
3.0.6-alpha.0.3 94.29 KB Sat, 01 Oct 2022 10:33:01 GMT 1
3.0.6-alpha.0.2 94.3 KB Mon, 26 Sep 2022 10:09:01 GMT 1
3.0.6-alpha.0.1 92.43 KB Tue, 28 Jun 2022 11:42:30 GMT 1
3.0.5-alpha.0.1 92.41 KB Thu, 16 Jun 2022 14:05:40 GMT 1
3.0.4-alpha.0.3 92.37 KB Fri, 15 Apr 2022 14:50:06 GMT 1
3.0.4-alpha.0.2 92.35 KB Fri, 15 Apr 2022 14:42:03 GMT 1
3.0.4-alpha.0.1 92.35 KB Fri, 15 Apr 2022 09:42:16 GMT 1
3.0.3-alpha.0.2 92.61 KB Tue, 05 Apr 2022 19:43:10 GMT 1
3.0.3-alpha.0.1 92.62 KB Mon, 04 Apr 2022 19:55:50 GMT 1
3.0.2-alpha.0.2 92.45 KB Sat, 26 Feb 2022 11:37:40 GMT 1
3.0.2-alpha.0.1 92.43 KB Mon, 21 Feb 2022 18:07:20 GMT 1
3.0.1-alpha.0.3 88.72 KB Sat, 12 Feb 2022 14:38:41 GMT 1
3.0.1-alpha.0.2 87.01 KB Sat, 12 Feb 2022 14:24:10 GMT 1
3.0.1-alpha.0.1 30.43 KB Thu, 10 Feb 2022 11:57:18 GMT 1
2.2.3-alpha.0.4 30.07 KB Mon, 31 Jan 2022 14:56:18 GMT 1
2.2.3-alpha.0.1 30.06 KB Mon, 31 Jan 2022 14:51:04 GMT 1
2.2.2-alpha.0.2 33.09 KB Thu, 21 Oct 2021 10:21:40 GMT 1
2.2.2-alpha.0.1 33.08 KB Thu, 21 Oct 2021 09:50:35 GMT 1
2.2.0-preview.1.2 33.01 KB Sun, 08 Aug 2021 18:55:30 GMT 1
2.2.0-preview.1.1 32.91 KB Sat, 10 Apr 2021 19:24:22 GMT 1
2.2.0-preview.0.3 32.91 KB Sat, 10 Apr 2021 18:53:17 GMT 1
2.2.0-preview.0.2 32.97 KB Sat, 10 Apr 2021 18:42:28 GMT 1
2.1.2-alpha.0.1 32.96 KB Sat, 10 Apr 2021 14:59:34 GMT 1
2.1.1-preview.0.1 63.52 KB Mon, 22 Feb 2021 16:05:21 GMT 1
2.1.1-alpha.2.3 63.51 KB Mon, 22 Feb 2021 15:25:37 GMT 1
2.1.1-alpha.1.2 62.35 KB Wed, 10 Feb 2021 19:24:50 GMT 1
2.1.1-alpha.0.2 62.06 KB Wed, 10 Feb 2021 15:00:27 GMT 1
2.1.1-alpha.0.1 60.5 KB Fri, 04 Dec 2020 12:38:07 GMT 1
2.0.3-preview.2.2 60.51 KB Fri, 27 Nov 2020 13:03:02 GMT 1
2.0.3-preview.2.1 60.04 KB Thu, 12 Nov 2020 20:17:30 GMT 1
2.0.3-preview.1.1 60.05 KB Thu, 12 Nov 2020 19:34:19 GMT 1
2.0.3-preview.0.2 31.13 KB Mon, 09 Nov 2020 11:49:44 GMT 1
2.0.3-preview.0.1 31.12 KB Mon, 09 Nov 2020 11:13:52 GMT 1
2.0.3-alpha.0.6 30.93 KB Mon, 02 Nov 2020 20:11:26 GMT 1
2.0.3-alpha.0.5 30.92 KB Mon, 02 Nov 2020 19:20:29 GMT 1
2.0.3-alpha.0.4 30.9 KB Thu, 29 Oct 2020 13:14:47 GMT 1
2.0.3-alpha.0.3 30.91 KB Thu, 29 Oct 2020 12:39:46 GMT 1
2.0.3-alpha.0.2 30.91 KB Thu, 29 Oct 2020 11:59:22 GMT 1
2.0.3-alpha.0.1 30.23 KB Mon, 26 Oct 2020 13:45:50 GMT 1
2.0.2-preview.1.1 30.23 KB Mon, 26 Oct 2020 12:56:22 GMT 1
2.0.2-preview.0.4 30.24 KB Thu, 22 Oct 2020 13:06:13 GMT 1
2.0.2-preview.0.3 30.24 KB Thu, 22 Oct 2020 10:11:19 GMT 1
2.0.2-preview.0.2 30.24 KB Fri, 18 Sep 2020 10:24:18 GMT 1
2.0.2-preview.0.1 30.24 KB Wed, 16 Sep 2020 17:29:46 GMT 1
2.0.2-alpha.0.2 30.23 KB Wed, 16 Sep 2020 16:56:55 GMT 1
2.0.2-alpha.0.1 30.48 KB Tue, 08 Sep 2020 15:00:27 GMT 1
2.0.1-preview-1 18.96 KB Tue, 21 Jul 2020 17:29:32 GMT 1
2.0.1-preview.1.2 30.48 KB Tue, 08 Sep 2020 14:15:04 GMT 1
2.0.1-preview.1.1 30.48 KB Fri, 04 Sep 2020 15:03:04 GMT 1
2.0.1-preview.0.2 30.49 KB Fri, 04 Sep 2020 14:27:01 GMT 1
2.0.1-preview.0.1 30.72 KB Thu, 27 Aug 2020 11:08:43 GMT 1
2.0.1-alpha.0.3 30.72 KB Wed, 26 Aug 2020 20:44:48 GMT 1
2.0.1-alpha.0.2 18.95 KB Thu, 20 Aug 2020 15:46:20 GMT 1
2.0.0 18.96 KB Wed, 08 Jul 2020 00:35:37 GMT 1
2.0.0-preview02 19.01 KB Mon, 06 Jul 2020 19:19:33 GMT 1
1.0.5 19.03 KB Mon, 25 May 2020 21:11:03 GMT 1
1.0.5-preview01 19.07 KB Mon, 25 May 2020 17:53:32 GMT 1
1.0.4 18.98 KB Sun, 24 May 2020 15:36:15 GMT 1
1.0.4-preview04 19.01 KB Sat, 23 May 2020 14:38:12 GMT 1
1.0.4-preview03 18.59 KB Sun, 17 May 2020 14:55:05 GMT 1
1.0.4-preview02 18.52 KB Sun, 17 May 2020 13:28:44 GMT 1
1.0.4-preview01 18.65 KB Thu, 14 May 2020 10:29:50 GMT 1
1.0.3 18.63 KB Wed, 13 May 2020 10:05:54 GMT 1
1.0.3-preview01 18.67 KB Sun, 03 May 2020 17:30:29 GMT 1
1.0.2 18.63 KB Sun, 03 May 2020 13:18:23 GMT 1
1.0.2-preview05 18.65 KB Sat, 02 May 2020 18:12:13 GMT 1
1.0.2-preview04 18.63 KB Wed, 29 Apr 2020 21:12:53 GMT 1
1.0.2-preview03 18.57 KB Tue, 28 Apr 2020 10:15:26 GMT 1
1.0.2-preview01 15.78 KB Tue, 21 Apr 2020 09:29:41 GMT 1
1.0.1 15.81 KB Sun, 08 Mar 2020 14:36:29 GMT 1
1.0.1-preview02 15.83 KB Wed, 05 Feb 2020 22:39:15 GMT 1
1.0.1-preview01 14.76 KB Tue, 04 Feb 2020 10:31:23 GMT 2
1.0.0 12.71 KB Wed, 11 Sep 2019 22:52:12 GMT 1
1.0.0-preview07 12.74 KB Mon, 09 Sep 2019 23:05:24 GMT 1
1.0.0-preview06 12.73 KB Mon, 09 Sep 2019 20:39:41 GMT 1