automapperdev - AutoMapper.AspNetCore.OData.EFCore 5.0.2-alpha.0.1

Creates LINQ expressions from ODataQueryOptions and executes the query.

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

Copy to clipboard

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

Copy to clipboard

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

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

nuget AutoMapper.AspNetCore.OData.EFCore  ~> 5.0.2-alpha.0.1
Copy to clipboard

> choco install AutoMapper.AspNetCore.OData.EFCore --version 5.0.2-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.EFCore" -RequiredVersion "5.0.2-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 v13 (EF Core only).

  • .NETFramework 6.0
    • AutoMapper.Extensions.ExpressionMapping (>= 7.0.0 && < 8.0.0)
    • LogicBuilder.Expressions.Utils (>= 6.0.0 && < 7.0.0)
    • Microsoft.AspNetCore.OData (>= 8.2.4)
    • Microsoft.EntityFrameworkCore (>= 6.0.0)
  • .NETFramework 7.0
    • AutoMapper.Extensions.ExpressionMapping (>= 7.0.0 && < 8.0.0)
    • LogicBuilder.Expressions.Utils (>= 6.0.0 && < 7.0.0)
    • Microsoft.AspNetCore.OData (>= 8.2.4)
    • Microsoft.EntityFrameworkCore (>= 7.0.0)
  • .NETFramework 8.0
    • AutoMapper.Extensions.ExpressionMapping (>= 7.0.0 && < 8.0.0)
    • LogicBuilder.Expressions.Utils (>= 6.0.0 && < 7.0.0)
    • Microsoft.AspNetCore.OData (>= 8.2.4)
    • Microsoft.EntityFrameworkCore (>= 8.0.2)
  • .NETFramework 6.0: 6.0.0.0
  • .NETFramework 7.0: 7.0.0.0
  • .NETFramework 8.0: 8.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

85 total downloads
0 downloads for version 5.0.2-alpha.0.1
Download (97.63 KB)
Download symbols (58.67 KB)
Found on the current feed only

Package history

Version Size Last updated Downloads Mirrored?
5.0.2-alpha.0.1 97.63 KB Sat, 06 Jul 2024 13:19:57 GMT 0
5.0.1-alpha.0.2 97.52 KB Wed, 12 Jun 2024 10:15:59 GMT 0
5.0.1-alpha.0.1 97.51 KB Wed, 12 Jun 2024 10:10:55 GMT 0
4.0.3-alpha.0.1 97.07 KB Mon, 19 Feb 2024 14:25:45 GMT 1
4.0.2-alpha.0.1 97.09 KB Thu, 28 Dec 2023 12:41:22 GMT 0
4.0.1-alpha.0.6 66.45 KB Sat, 19 Aug 2023 12:33:33 GMT 2
4.0.1-alpha.0.5 66.45 KB Fri, 18 Aug 2023 17:14:51 GMT 1
4.0.1-alpha.0.4 96.81 KB Tue, 17 Jan 2023 21:18:20 GMT 1
4.0.1-alpha.0.3 96.78 KB Mon, 16 Jan 2023 21:28:30 GMT 1
4.0.1-alpha.0.2 96.59 KB Fri, 11 Nov 2022 17:04:12 GMT 1
4.0.1-alpha.0.1 96.57 KB Fri, 11 Nov 2022 16:12:49 GMT 1
3.0.7-alpha.0.1 96.61 KB Sat, 01 Oct 2022 12:13:25 GMT 1
3.0.6-alpha.0.3 96.59 KB Sat, 01 Oct 2022 10:32:57 GMT 1
3.0.6-alpha.0.2 96.61 KB Mon, 26 Sep 2022 10:08:57 GMT 1
3.0.6-alpha.0.1 94.65 KB Tue, 28 Jun 2022 11:42:24 GMT 1
3.0.5-alpha.0.1 94.64 KB Thu, 16 Jun 2022 14:05:34 GMT 1
3.0.4-alpha.0.3 94.58 KB Fri, 15 Apr 2022 14:50:01 GMT 1
3.0.4-alpha.0.2 94.56 KB Fri, 15 Apr 2022 14:41:57 GMT 1
3.0.4-alpha.0.1 94.57 KB Fri, 15 Apr 2022 09:42:11 GMT 1
3.0.3-alpha.0.2 94.83 KB Tue, 05 Apr 2022 19:42:54 GMT 1
3.0.3-alpha.0.1 94.87 KB Mon, 04 Apr 2022 19:55:45 GMT 1
3.0.2-alpha.0.2 94.68 KB Sat, 26 Feb 2022 11:37:35 GMT 1
3.0.2-alpha.0.1 94.68 KB Mon, 21 Feb 2022 18:07:15 GMT 1
3.0.1-alpha.0.3 90.93 KB Sat, 12 Feb 2022 14:38:36 GMT 1
3.0.1-alpha.0.2 89.2 KB Sat, 12 Feb 2022 14:24:05 GMT 1
3.0.1-alpha.0.1 31.19 KB Thu, 10 Feb 2022 11:57:14 GMT 1
2.2.3-alpha.0.4 30.82 KB Mon, 31 Jan 2022 14:56:14 GMT 1
2.2.3-alpha.0.1 30.82 KB Mon, 31 Jan 2022 14:50:58 GMT 1
2.2.2-alpha.0.2 33.9 KB Thu, 21 Oct 2021 10:21:33 GMT 1
2.2.2-alpha.0.1 33.9 KB Thu, 21 Oct 2021 09:50:26 GMT 1
2.2.0-preview.1.2 33.8 KB Sun, 08 Aug 2021 18:55:21 GMT 1
2.2.0-preview.1.1 33.69 KB Sat, 10 Apr 2021 19:24:15 GMT 1
2.2.0-preview.0.3 33.69 KB Sat, 10 Apr 2021 18:53:09 GMT 1
2.2.0-preview.0.2 33.73 KB Sat, 10 Apr 2021 18:42:19 GMT 1
2.1.2-alpha.0.1 33.73 KB Sat, 10 Apr 2021 14:59:26 GMT 1
2.1.1-preview.0.1 33.67 KB Mon, 22 Feb 2021 16:05:14 GMT 1
2.1.1-alpha.2.3 33.67 KB Mon, 22 Feb 2021 15:25:29 GMT 1
2.1.1-alpha.1.2 33.1 KB Wed, 10 Feb 2021 19:24:42 GMT 1
2.1.1-alpha.0.2 33.11 KB Wed, 10 Feb 2021 15:00:19 GMT 1
2.1.1-alpha.0.1 32.36 KB Fri, 04 Dec 2020 12:38:00 GMT 1
2.0.3-preview.2.2 32.36 KB Fri, 27 Nov 2020 13:02:55 GMT 1
2.0.3-preview.2.1 32.12 KB Thu, 12 Nov 2020 20:17:22 GMT 1
2.0.3-preview.1.1 32.11 KB Thu, 12 Nov 2020 19:34:11 GMT 1
2.0.3-preview.0.2 32.1 KB Mon, 09 Nov 2020 11:49:37 GMT 1
2.0.3-preview.0.1 32.11 KB Mon, 09 Nov 2020 11:13:44 GMT 1
2.0.3-alpha.0.6 31.88 KB Mon, 02 Nov 2020 20:11:18 GMT 1
2.0.3-alpha.0.5 31.88 KB Mon, 02 Nov 2020 19:20:21 GMT 1
2.0.3-alpha.0.4 31.86 KB Thu, 29 Oct 2020 13:14:39 GMT 1
2.0.3-alpha.0.3 31.86 KB Thu, 29 Oct 2020 12:39:35 GMT 1
2.0.3-alpha.0.2 31.86 KB Thu, 29 Oct 2020 11:59:14 GMT 1
2.0.3-alpha.0.1 31.18 KB Mon, 26 Oct 2020 13:45:42 GMT 1
2.0.2-preview.1.1 31.18 KB Mon, 26 Oct 2020 12:56:15 GMT 1
2.0.2-preview.0.4 31.19 KB Thu, 22 Oct 2020 13:06:04 GMT 1
2.0.2-preview.0.3 31.19 KB Thu, 22 Oct 2020 10:11:09 GMT 1
2.0.2-preview.0.2 31.2 KB Fri, 18 Sep 2020 10:24:10 GMT 1
2.0.2-preview.0.1 31.19 KB Wed, 16 Sep 2020 17:29:37 GMT 1
2.0.2-alpha.0.2 31.19 KB Wed, 16 Sep 2020 16:56:46 GMT 2
2.0.2-alpha.0.1 32.68 KB Tue, 08 Sep 2020 15:00:18 GMT 1
2.0.1-preview-1 19.86 KB Tue, 21 Jul 2020 17:29:25 GMT 1
2.0.1-preview.1.2 32.68 KB Tue, 08 Sep 2020 14:14:55 GMT 1
2.0.1-preview.1.1 32.69 KB Fri, 04 Sep 2020 15:02:55 GMT 1
2.0.1-preview.0.2 32.69 KB Fri, 04 Sep 2020 14:26:52 GMT 1
2.0.1-preview.0.1 32.86 KB Thu, 27 Aug 2020 11:08:34 GMT 1
2.0.1-alpha.0.3 32.87 KB Wed, 26 Aug 2020 20:44:39 GMT 1
2.0.1-alpha.0.2 19.85 KB Thu, 20 Aug 2020 15:46:12 GMT 1
2.0.0 19.86 KB Wed, 08 Jul 2020 00:35:38 GMT 1
2.0.0-preview02 19.92 KB Mon, 06 Jul 2020 19:19:34 GMT 1
1.0.5 19.93 KB Mon, 25 May 2020 21:11:04 GMT 1
1.0.5-preview01 19.98 KB Mon, 25 May 2020 17:53:33 GMT 1
1.0.4 19.9 KB Sun, 24 May 2020 15:36:15 GMT 1
1.0.4-preview04 19.93 KB Sat, 23 May 2020 14:38:13 GMT 1
1.0.4-preview03 19.54 KB Sun, 17 May 2020 14:55:06 GMT 1
1.0.4-preview02 19.48 KB Sun, 17 May 2020 13:28:45 GMT 1
1.0.4-preview01 19.46 KB Thu, 14 May 2020 10:29:50 GMT 1
1.0.3 19.44 KB Wed, 13 May 2020 10:05:56 GMT 1
1.0.3-preview01 19.48 KB Sun, 03 May 2020 17:30:30 GMT 1
1.0.2 19.41 KB Sun, 03 May 2020 13:18:24 GMT 1
1.0.2-preview05 19.44 KB Sat, 02 May 2020 18:12:14 GMT 1
1.0.2-preview04 19.41 KB Wed, 29 Apr 2020 21:12:54 GMT 1
1.0.2-preview03 19.38 KB Tue, 28 Apr 2020 10:15:27 GMT 1
1.0.2-preview01 16.66 KB Tue, 21 Apr 2020 09:29:42 GMT 1
1.0.1 16.64 KB Sun, 08 Mar 2020 14:36:29 GMT 1
1.0.1-preview02 16.67 KB Wed, 05 Feb 2020 22:39:16 GMT 1
1.0.1-preview01 15.54 KB Tue, 04 Feb 2020 10:31:24 GMT 1
1.0.0 13.51 KB Wed, 11 Sep 2019 22:52:13 GMT 1
1.0.0-preview07 13.54 KB Mon, 09 Sep 2019 23:05:25 GMT 1
1.0.0-preview06 13.54 KB Mon, 09 Sep 2019 20:39:42 GMT 1