EFQueryMapper 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package EFQueryMapper --version 1.0.2                
NuGet\Install-Package EFQueryMapper -Version 1.0.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="EFQueryMapper" Version="1.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EFQueryMapper --version 1.0.2                
#r "nuget: EFQueryMapper, 1.0.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install EFQueryMapper as a Cake Addin
#addin nuget:?package=EFQueryMapper&version=1.0.2

// Install EFQueryMapper as a Cake Tool
#tool nuget:?package=EFQueryMapper&version=1.0.2                

EFQueryMapper

EFQueryMapper is a powerful library for seamless type mapping, including support for Entity Framework's IQueryable interface. It allows for efficient mapping between entities and DTOs, streamlining the data transformation process in .NET applications.

Installation

You can install the package via NuGet Package Manager:

Install-Package EFQueryMapper

Or via .NET CLI:

dotnet add package EFQueryMapper

Usage

You can add it to DI this way:

 services.AddQueryMapper<BookMapper>()

Your custom mapper must be a subclass of QueryMapper. It is a MUST since QueryMapper itself already covers all the heavy stuff and implements IQueryMapper readily with a flexible way. Let's take a look at an example:

 public class BookMapper : QueryMapper
 {
     public BookMapper()
     {
         Configure<Person, PersonDTO>(config =>
         {
             config
             .Match(x => x.Firstname + " " + x.Lastname, dto => dto.Fullname)
             .UsingConstructor(x => new PersonDTO(x.Firstname, x.Lastname))
             ;
         });

         Configure<Book, ReadBookResponse>(config =>
         {
             config
             .Match(x => x.Author.FirstName + " " + x.Author.LastName, y => y.AuthorName)
             .Match(x => x.CreatedBy.FirstName + " " + x.CreatedBy.LastName, y => y.CreatedByName)
             ;
         });

         Configure<Note, ReadNoteResponse>(config =>
         {
             config
             .Match(x => x.User.FirstName + " " + x.User.LastName, y => y.UserName)
             .Match(x => x.User.ShareId, y => y.ShareId)
             ;
         });
     }
 }

You see we have "Configure" method. It has a couple methods to extend mapping abilities:

UsingConstructor: Allows you to use the constructor you wish. If destination class has multiple constructors and you want to pick a certain one, this method would be useful. If you don't use and map straight, first constructor found will be used. Private constructors are NOT prioritized while picking up constructor automatically.

Lets say you have only one constructor and it has parameters. You don't need to use this method if parameter names are matched to related property/field. Imagine you have only this constructor:

 private PersonDTO(string firstname)
 {
     Firstname = firstname;
 }

Even if it is private, it is easily used with mapper. If you have multiple constructors, the ones who are not private have priority to be picked up by mapper. Since member names are matched, you don't have to make any configurations. If namings don't match just use the method.

Example

You can easily use Map method directly with IQueryable interface. Here's a quick example:

IQueryable<Person> peopleQuery = dbcontext.Person.Where(x=> x.Age >= 18);
List<PersonDTO> extensionQueryPeople = peopleQuery.Map<PersonDTO>(mapper).ToList();

Or you can go this way:

List<PersonDTO> value = mapper.Map<Person, PersonDTO>(peopleQuery).ToList();

Features

  • Supports Entity Framework IQueryable interface
  • Seamless mapping between entities and DTOs
  • Optimized for performance with the help of Expression API

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on EFQueryMapper:

Package Downloads
QueryBase

This library provides a powerful generic repository base, leveraging the capabilities of Entity Framework and QueryMapper. It simplifies CRUD operations, making them easily extendable. Pagination, filtering, ordering, and bulk operations are all implemented in a generic and flexible way. Most methods can be overridden for customization.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.5 118 10/20/2024
1.0.4 81 10/15/2024
1.0.3 85 10/9/2024
1.0.2 76 10/7/2024
1.0.1 81 10/7/2024
1.0.0 86 10/2/2024

type check mini fix