automapper / automapper.ef6 Goto Github PK
View Code? Open in Web Editor NEWExtensions for AutoMapper and EF6
License: MIT License
Extensions for AutoMapper and EF6
License: MIT License
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
Hi, the nuget package is outdated and targets .NETFramework 4.6.1 but not .NETStandard, can you please update the nuget package?
Thanks
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
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; }
}
mapper.CreateMap<TestStepRun, TestStepRunDto>();
EF 6.0.1.0
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.
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.
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;
}
Is there a way we can get AutoMapper.EF6 to work with all versions of EF6 and not just EF 6.1.3?
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.
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.
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)
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 ?
Any plans to support EF Core 2.0?
As I told in the title, is it possible to map dtos to entities with relations included?
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;}
}
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();
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!
EF 6.4 was ported to NETSTANDARD/NETCORE, could you please support these target frameworks too?
Thank you, Tomas
Hi,
i want to save color into a database and read it back. Therefore i use an INT in the database. I implemented TypeConverters. While reading the entries from the database i got a System.ArgumentException.
Maybe i doing wrong. Please see attached project. Thank you.
regards
Kai
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
Installed AutoMapper v6.0.0.0 (released today), project no longer builds
Any plans to support EF7?
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?
I'm using EF6.4, and I need to pass an instance into GenerateEntityFrameworkPrimaryKeyPropertyMaps() instead of it doing a new.
Is it possible to add another ctor? (I'm currently using a custom version of GenerateEntityFrameworkPrimaryKeyPropertyMaps to achieve this.)
public GenerateEntityFrameworkPrimaryKeyPropertyMaps(TDatabaseContext dbContext)
{
_context = dbContext;
}
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);
I would love to see this happening for EF Core.
Thanks in advance and keep up the good work!
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?
Possibly other extensions may be broken when using Automapper 4.1.1
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>());
});
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.