automapper-3

Automapper and mapping list within a complex object / nested mappings

ε祈祈猫儿з 提交于 2020-08-21 06:45:57
问题 I am having a heck of a time converting from older mapping standards to automapper. Here are my classes // Models public class BaseModel { public Int64 Id { get; set; } public Guid UniqueId { get; set; } public DateTime? CreateDate { get; set; } public DateTime? LastUpdate { get; set; } } public class LibraryItemModel : BaseModel { public string Name { get; set; } public string Description { get; set; } public string URL { get; set; } public bool IsActive { get; set; } public List

AutoMapper null source value and custom type converter, fails to map?

时光总嘲笑我的痴心妄想 提交于 2020-01-14 13:07:50
问题 When using a custom type converter (ITypeConverter) with AutoMapper it does not seem to enter the type converters code if the source value is null , e.g: Mapper.CreateMap<string, Enum>().ConvertUsing<EnumConverter>(); Assert.AreEqual(Enum.Value1, Mapper.Map<Enum>("StringValue1")); Assert.AreEqual(Enum.Value1, Mapper.Map<Enum>(null); Assert.AreEqual(Enum.Value1, Mapper.Map<Enum?>(null); The type converter looks something like: public class EnumConvertor: ITypeConverter<string, Enum> { public

Automapper - Not copying from source to destination object correctly. Errors need default constructor

心不动则不痛 提交于 2020-01-06 04:15:50
问题 When I map a source object into an existing instance it appears to want to create a new object and not copy into... Here is my test scenario: List<DomainCustomerProxy> domainCustomers = customers.Select(customer => new DomainCustomerProxy( new Lazy<List<DomainContact>>(() => RetrieveContactsByCustomerId(customer.Id, lazyLoad, schemaName).ToList(), LazyThreadSafetyMode.ExecutionAndPublication), new Lazy<List<DomainDepartment>>(() => RetrieveDepartmentsByCustomerId(customer.Id, lazyLoad,

Automapper - Not copying from source to destination object correctly. Errors need default constructor

别来无恙 提交于 2020-01-06 04:15:46
问题 When I map a source object into an existing instance it appears to want to create a new object and not copy into... Here is my test scenario: List<DomainCustomerProxy> domainCustomers = customers.Select(customer => new DomainCustomerProxy( new Lazy<List<DomainContact>>(() => RetrieveContactsByCustomerId(customer.Id, lazyLoad, schemaName).ToList(), LazyThreadSafetyMode.ExecutionAndPublication), new Lazy<List<DomainDepartment>>(() => RetrieveDepartmentsByCustomerId(customer.Id, lazyLoad,

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(),

IQueryable Extension Behavior Differing For Automapper Polymorphic Collection

爱⌒轻易说出口 提交于 2019-12-22 01:18:45
问题 Using Automapper 3.3.1.0 there is a different mapping behavior between the usage of Mapper.Map<IEnumerable<TDestination>>(someEnumerable) compared to someEnumerable.AsQueryable().Project().To<TDestination>() This does not appear to be a limitation of a SQL LINQ provider or other as this is witnessed in an in-memory collection. As with many things this is best explained by example: Note: the following code can be found at https://gist.github.com/kmoormann/b3949d006f4083ab6ee4 using System

Automapper: passing parameter to Map method

让人想犯罪 __ 提交于 2019-12-20 11:49:38
问题 I'm using Automapper in a project and I need to dynamically valorize a field of my destination object. In my configuration I have something similar: cfg.CreateMap<Message, MessageDto>() // ... .ForMember(dest => dest.Timestamp, opt => opt.MapFrom(src => src.SentTime.AddMinutes(someValue))) //... ; The someValue in the configuration code is a parameter that I need to pass at runtime to the mapper and is not a field of the source object. Is there a way to achieve this? Something like this:

AutoMapper's Ignore() not working when using ForSourceMember?

左心房为你撑大大i 提交于 2019-12-19 18:48:13
问题 I'm trying to ignore a property from source type. I have defined mapping like this: var map = AutoMapper.Mapper.CreateMap<Article, IArticle>(); map.ForSourceMember(s => s.DateCreated, opt => opt.Ignore()); map.ForSourceMember(s => s.DateUpdated, opt => opt.Ignore()); When I call Map function, AutoMapper.Mapper.Map(article, articlePoco); destination's properties gets updated anyway. I'm using the latest stable version downloaded from NuGet. Any ideas why this isn't working ? I have found

AutoMapper.Mapper.CreateMap<TSource,TDestination>()' is obsolete

a 夏天 提交于 2019-12-18 13:04:29
问题 I have to classes Like class A { public int id {get; set;} } class B { public C c {get; set;} } class C { public int id {get; set;} public string Name {get; set;} } My requirement is to map id of class A to id of class C. Now what I was doing till now was: Mapper.CreateMap().ForMember(des => des.C.Id, src => src.MapFrom(x => x.id)); and it was working fine. Now seems like Auto mapper has changed their implementation. and I am getting warning as below: AutoMapper.Mapper.CreateMap()' is

Automapper with linq how?

天涯浪子 提交于 2019-12-14 02:25:37
问题 Ok, I'm really struggling with finding a good example of what I need to do. So, I'll ask here. Let's say I have a entity class (EF) named Customer and a corresponding view-model class named CustomerViewModel. Using AutoMapper, I have created the following mappings: Mapper.CreateMap<CustomerViewModel, Customer>(); Mapper.CreateMap<Customer, CustomerViewModel>(); How would I modify the following code to make use of this mapping? public static List<CustomerViewModel> GetCustomers() { using (var