automapper

AutoMapper 3.1.1 and Entity Framework 6.1 Proxy objects

丶灬走出姿态 提交于 2020-01-11 06:16:38
问题 I realized this has been asked already, but the solutions I've read don't seem to make a difference so far. I'm using Entity Framework 6.1 and AutoMapper 3.1.1. Taking the following objects: Company and CompanyListItem ; I try this: Mapper.Configure<Company, CompanyListItem>(); Well, when I try to do the actual mapping it crashed and burned with an exception that there's no mappings defined. I know this is caused because of the proxy objects created by Entity Framework. One solutions I've

How do I get AutoMapper to deal with a custom naming convention?

泪湿孤枕 提交于 2020-01-11 03:05:05
问题 In the project I'm working on, we are mapping auto-generated DTOs to business objects. The database has an ahem unusual (but largely consistent) naming convention, which means that it's possible to transform most DTO property names to their equivalent business object property names, thus saving many lines of code. For example, in the DTO (and database) we have a property called account_ID__created that will map to a BO property called CreatedAccountId . This is the kind of transformation

Replace Ninject with Simple Injector

假装没事ソ 提交于 2020-01-10 11:33:47
问题 I've used Ninject for my application. Ninject is really simple and easy to learn, but its quite slow and I try to use another IoC to compare if its faster as with Ninject. There are a lot of IoC containers for MVC3 and Simple Injector looks really good to me, but I've a lot of problems with replacting Ninject with Simple Injector. Especially with the AutoMapper . I try to convert this lines into Simple Injector code. Bind<ITypeMapFactory>().To<TypeMapFactory>(); foreach (var mapper in

Automapper projection and union

陌路散爱 提交于 2020-01-07 03:08:17
问题 I have a problem with union and automapper projections. I have two entities: public class Entity { public DateTime ActionDate { get; set; } public int SomeProp { get; set; } } public class ExtendedEntity { public DateTime ActionDate { get; set; } public int SomeProp { get; set; } public int SomeOtherProp { get; set; } } and projection: public class EntityProjection { public DateTime ActionDate { get; set; } public int SomeProp { get; set; } public int SomeOtherProp { get; set; } public string

static constructor not invoked

那年仲夏 提交于 2020-01-06 21:11:00
问题 I'm trying to use the AutoMapper for model-viewmodel mapping and wanted to have the mapping configuration executed once in the static constructor of the type. The static constructor of a type is not invoked when Mapper.Map (AutoMapper) is invoked with that type. My understanding is that the Mapper.Map would try to access the type, its members through reflection and on the first attempt of the usage the static constructor would be called. This is something basic but challenges my understanding

Automapper, mapping to a complex object

孤者浪人 提交于 2020-01-06 14:55:45
问题 I have 2 classes i'm trying to map namely 1) Entity 2) DTO I'm trying to map Entity.Foo to DTO.Child.Foo Obviously the below will not work, how do I achieve this. I need to create a new instance of Child and then attach that to the Mapper and then set the Foo property but my AutoMapper skills are not that good! Mapper.CreateMap<Entity, DTO>() .ForMember("Child.Foo", m => m.MapFrom(entity => entity.Foo)) 回答1: Mapper.CreateMap<Entity, DTO>() .ForMember(d => d.Foo, o => o.ResolveUsing(s => new

How to use AutoMapper 9.0.0 in Asp.Net Web Api 2 without dependency injection?

北城以北 提交于 2020-01-06 07:53:56
问题 I haven't been able to find any info where to put this code inside my project. Right now I am use using this in each action I need the mapper. Is there a better way to do this with out dependency injection? var config = new MapperConfiguration(cfg => { cfg.CreateMap<Source, Dest>(); }); IMapper iMapper = config.CreateMapper(); var destList= iMapper.Map<Dest[]>(sourceList); 回答1: Dependency injection added a whole level of complexity to my legacy project that I just didn't want to deal with. 9

AutoMapper hurting performance in .net application having more than 1327 DTO while mapping

折月煮酒 提交于 2020-01-06 04:01:27
问题 We are using AutoMapper 3.1.1.0 in our Dot net application. We are having lots of classes which neeed to map. Time required to initialize mapping is almost 22 seconds. We are having almost 1327 DTO which need to mapped. And we can say that each DTO having average 8 properties. My concern is for each message we check in list of 1327 mapped DTO, and then use if (MappingManager.MessageMappings.ContainsKey(message.GetType())) { var myMessage = Mapper.Map(message, message.GetType(),

How to pass a service from .net core di container to a new object created with automapper

佐手、 提交于 2020-01-05 04:16:30
问题 I'm facing a scenario where I need to inject a service from asp.net core DI container to the constructor of an object created using automapper. I don't know if this is the best practice but let me explain what I'm trying to accomplish. I've an asp.net core mvc controller that receives a model parameter, just a POCO, that model needs to be converted into a ViewModel class that contains some business logic, data access etc, in that class object I want to get some info from the injected service,

automapper map collections with action

*爱你&永不变心* 提交于 2020-01-04 04:34:11
问题 I have the following code IList<ConfigurationDto> result = new List<ConfigurationDto>(); foreach (var configuration in await configurations.ToListAsync()) { var configurationDto = _mapper.Map<ConfigurationDto>(configuration); configurationDto.FilePath = _fileStorage.GetShortTemporaryLink(configuration.FilePath); result.Add(configurationDto); } return result; How can I use automapper instead if foreach? I can map collection, but how to call _fileStorage.GetShortTemporaryLink for each item? I