Giter VIP home page Giter VIP logo

automapper.ef6's Introduction

AutoMapper

CI NuGet MyGet (dev) Documentation Status

What is AutoMapper?

AutoMapper is a simple little library built to solve a deceptively complex problem - getting rid of code that mapped one object to another. This type of code is rather dreary and boring to write, so why not invent a tool to do it for us?

This is the main repository for AutoMapper, but there's more:

How do I get started?

First, configure AutoMapper to know what types you want to map, in the startup of your application:

var configuration = new MapperConfiguration(cfg => 
{
    cfg.CreateMap<Foo, FooDto>();
    cfg.CreateMap<Bar, BarDto>();
});
// only during development, validate your mappings; remove it before release
#if DEBUG
configuration.AssertConfigurationIsValid();
#endif
// use DI (http://docs.automapper.org/en/latest/Dependency-injection.html) or create the mapper yourself
var mapper = configuration.CreateMapper();

Then in your application code, execute the mappings:

var fooDto = mapper.Map<FooDto>(foo);
var barDto = mapper.Map<BarDto>(bar);

Check out the getting started guide. When you're done there, the wiki goes in to the nitty-gritty details. If you have questions, you can post them to Stack Overflow or in our Gitter.

Where can I get it?

First, install NuGet. Then, install AutoMapper from the package manager console:

PM> Install-Package AutoMapper

Or from the .NET CLI as:

dotnet add package AutoMapper

Do you have an issue?

First check if it's already fixed by trying the MyGet build.

You might want to know exactly what your mapping does at runtime.

If you're still running into problems, file an issue above.

License, etc.

This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behavior in our community. For more information see the .NET Foundation Code of Conduct.

AutoMapper is Copyright © 2009 Jimmy Bogard and other contributors under the MIT license.

.NET Foundation

This project is supported by the .NET Foundation.

automapper.ef6's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

automapper.ef6's Issues

Add support for netcoreapp1.0

When trying to install in an ASP.NET Core 1.0 project with AutoMapper v5.0.0 installed, AutoMapper.EF6 fails to restore with the following error:

Package AutoMapper.EF6 0.4.0 is not compatible with netcoreapp1.0 (.NETCoreApp,Version=v1.0). Package AutoMapper.EF6 0.4.0 supports: net45 (.NETFramework,Version=v4.5)

Possibility to update System.Data.SqlClient to version >=4.8.5?

Good day,

I'm recieveing warnings by my IDE that "Transitive dependency System.Data.SqlClient 4.8.1 contains vulnerabilities according to
Checkmarx©", and there is, in fact, an official Microsoft report on the vulnerability (which indicates a medium security risk) and that it has been fixed in version 4.8.5.

In theory, to fix it, its only necessary to update the Nuget Package.
Would that be possible?
Thanks a lot

ProjectTo<T> should support excluding [NotMapped] or explicitly provided entity properties

Source/destination types

Entity:

public class TestStepRun : MultiTenantEntity
{
    public int TestStepId { get; set; }

    public TestStep TestStep { get; set; }

	[NotMapped]
    public NetworkEvent NetworkEvent { get; set; }

	[NotMapped]
    public ConsoleLogEvent ConsoleLogEvent { get; set; }

    public bool? Passed { get; set; }
}

DTO:

public class TestStepRunDto
{
    public int? Id { get; set; }

    public int TestStepId { get; set; }

    public bool? Passed { get; set; }

    public NetworkEventDto NetworEvent { get; set; }

    public ConsoleLogEventDto ConsoleLogEvent { get; set; }
}

Mapping configuration

mapper.CreateMap<TestStepRun, TestStepRunDto>();

Version: 12.0.0.0

EF 6.0.1.0

Expected behavior

The mapper to work out that NetworkEvent and ConsoleLogEvent are not actually part of the entity in the DB and exclude these from the projection expression.

My use case here is that the two NotMapped properties are part of my domain model however not part of a relational DB, these are persisted in blob storage and my repository is responsible for handling the persistence and retrieval/hydration of my entity from the two data sources.

Actual behavior

EF tries to project these NotMapped properties using the mapping configuration and fails stating it cannot translate the query, likely due to the fact that it can't find a table for those properties to translate the expression to.

Steps to reproduce

public async Task<TData> GetLastWithDetailsAsync<TData>(int testCaseId, IConfigurationProvider configurationProvider)
{
    var result = await this.DbContext.Set<TestCaseRun>()
        .Where(x => x.TestCaseId == testCaseId)
        .OrderByDescending(x => x.Id)
        .ProjectTo<TData>(configurationProvider)
        .FirstOrDefaultAsync()
        .ConfigureAwait(false); 

    return result;
}

Pass MapperConfigurationExpression?

I usually use Automapper with a custom MapperConfigurationExpression to, among other things, set CreateMissingTypeMaps = true (yes, I am aware of the consequences).

Is there a way to pass the configuration to the extension? How will this work with a non-static mapper?

error in Linq handling for ProjectTo method

Hi

I error for projecting some DTO to entity
my entity has a relation called ModuleFile and my DTO has it by ModuleFileDTO but in this case it can't handle this and throws this error

System.InvalidOperationException: The LINQ expression 'dtoModuleFile => new ModuleFileDto{ 

    Created = dtoModuleFile.Created, 

    Description = dtoModuleFile.Description, 

    Duration = dtoModuleFile.Duration, 

    FileName = dtoModuleFile.FileName, 

    FilePath = dtoModuleFile.FilePath, 

    FileSize = dtoModuleFile.FileSize, 

    FileType = dtoModuleFile.FileType, 

    Id = dtoModuleFile.Id, 

    IsDeleted = dtoModuleFile.IsDeleted, 

    LastModified = dtoModuleFile.LastModified, 

    MimeType = dtoModuleFile.MimeType, 

    ModuleFileContents = dtoModuleFile.ModuleFileContents

        .Select(dtoModuleFileContent => new ModuleFileContentDto{ 

            CropData = dtoModuleFileContent.CropData, 

            Description = dtoModuleFileContent.Description, 

            HasWatermark = dtoModuleFileContent.HasWatermark, 

            ModuleFileId = dtoModuleFileContent.ModuleFileId, 

            ModuleType = dtoModuleFileContent.ModuleType, 

            Usage = dtoModuleFileContent.Usage 

        }

        )

        .ToList(), 

    ParentId = dtoModuleFile.ParentId, 

    Photographer = dtoModuleFile.Photographer 

}

' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.

How can i solve this ?

EF7?

Any plans to support EF7?

Strongly signed

Hi,

I am having an issue registering the Nuget package into the GAC. I know it's not ideal, but that's how they are doing things here. I am getting an error indicating that the DLL is not strongly signed. Is this something that will change in the future?

Tim

DLLs in NuGet packages appear not to be signed

I just tried the last three versions of AutoMapper.EF6 in a project in which my assembilies were signed and the AutoMapper.EF6 dll would fail to load. The message was something on the order of "a strongly named assembly is needed". I looked at the dll with ILDASM and did not see the required key information.

how to use?

hello I have nuget installed this pkg. I added "using Automapper" to class file (namespace ".EF6" doesn't exist). I write "Mapper.CreateMap...." and get error "Mapper does not contain a definition for CreateMap".
How to use this pkg?

Package version 1.0.0 on NuGet appears broken

as per title - 0.6.0 works for me, 1.0.0 attempts to reference AutoMapper.dll 0.0.0, and fails.
Additionally, looks like the code here claims to be version 0.6.0 anyway - 1.0.0 is also 7 months old, vs 0.6.0 being 2 months old.

Nuget package targets outdated

Hi, the nuget package is outdated and targets .NETFramework 4.6.1 but not .NETStandard, can you please update the nuget package?

Thanks

Can't use IValueConverter

public class CurrencyFormatter : IValueConverter<decimal, string> {
public string Convert(decimal source)
=> source.ToString("c");
}

Mapper.Initialize(cfg => {
cfg.CreateMap<Order, OrderDto>()
.ForMember(d => d.Amount, opt => opt.ConvertUsing<CurrencyFormatter, decimal>());
cfg.CreateMap<OrderLineItem, OrderLineItemDto>()
.ForMember(d => d.Total, opt => opt.ConvertUsing<CurrencyFormatter, decimal>());
});

When I try to translate enum to string,I get a exception

Hi:
This tool is really powerful, but I get some problem,can you help me?

My POCO has some properties uses enum type,and when I try to map this POCO to my DTO(Data transfer object) which mapping properties uses string type, my program throw a exception; it said: EF can not translate some method(sorry I forget the method name...)

by the way, I put Enum.GetName method into Automapper config.... maybe it is root cause, but what if I really want this feature, what is best practice?

State of 2.1.0

Hi!

Quick question, what would be the state of the current 2.1.0 version?
I am asking this because our software has a dependency on EF6.2. We would like to update to 6.4 so that we can make our applications to run on multiple platforms.

Currently this package is the last dependency that prevents us from doing this. As far we did notice, is that there is already a 2.1.0 version on your development nuget server. Is this package as well ready to be pushed towards the official nuget.org server?

Thanks in advance!

Kind Regards,
Mattletw

[Question] Can I use AutoMapper.EF to map Dtos to entities (including nested included relations)?

As I told in the title, is it possible to map dtos to entities with relations included?

Example model

class Product {
  public int Id {get;set;}
  public string Name {get;set;}
  public List<ProductStore> Stores {get;set}
}

class ProductStore {
  public int Id {get;set;}
  public int ProductId {get;set;}
  public int StoreId {get;set;}
  
  public Product Product {get;set;}
  public Store Store {get;set;}

  public decimal Price {get;set;}
}

What I need?

public async Task<ActionResult> PutProduct(int id, [FromBody]Product doc)
{
    var product = await _context.Products.Incude(p => p.Stores).SingleOrDefaultAsync(p => p.Id == id);

    // A magic method to map dto (which is also same type as data model) to connected model
    Map(doc, product);

    /*
      *  Magic function from AutoMapper executes:
      *
      *  product.Name = doc.Name;
      *  product.Stores[0].Price = doc.Stores[0].Price;
      */

    await _context.SaveChangesAsync();
    return Ok();

WHY?

Otherwise I had to manually map each field also manually modify nested lists (eg add new items, remove item if not exists in doc, or modify exists items) which makes my code repeat itself.

So, can AutoMapper help me to solve this issue? Or do you have any other suggestions for modifying data. Thanks!

EntityFramework Version

Is there a way we can get AutoMapper.EF6 to work with all versions of EF6 and not just EF 6.1.3?

Default value on "...OrDefault" operations

Would be nice in "OrDefault" operations if had an overload that accepts an default object of the same TSource's type to project, like main Linq "OrDefault" operations where you can pass an default value.

Like this overload from Linq
public static TSource FirstOrDefault<TSource>(this IQueryable<TSource> source, TSource defaultValue);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.