automapper-3

AutoMapper TwoWay Mapping with same Property Name

China☆狼群 提交于 2019-12-12 09:41:51
问题 Given these two objects public class UserModel { public string Name {get;set;} public IList<RoleModel> Roles {get;set;} } public class UserViewModel { public string Name {get;set;} public IList<RoleViewModel> Roles {get;set;} // notice the ViewModel } Is this the most optimal way to do the mapping, or is AutoMapper capable of mapping Roles to Roles on its own? App Config Mapper.CreateMap<UserModel, UserViewModel>() .ForMember(dest => dest.Roles, opt => opt.MapFrom(src => src.Roles)); Mapper

“Missing type map configuration or unsupported mapping” after deploying

天涯浪子 提交于 2019-12-11 00:45:48
问题 Each time after I deploy my code into IIS I keep getting the error "Missing type map configuration or unsupported mapping". Once I restart IIS, the problem goes away, so I don't think it's my code. However, today, I am continuing to get this error. The mapping error initially happened in one place and after restarting, it is now happening on different mappings, so it's not always the same place. Is there anything with a release into IIS that would cause Automapper to use a previously "cached"

Automapper, mapping single destination property as a concatenation of multiple source property

六眼飞鱼酱① 提交于 2019-12-10 04:35:48
问题 I have a situation where I need to map a single property as a combination of multiple source properties based on some conditions. Destination : public class Email { public Email() { EmailRecipient = new List<EmailRecipient>(); } public string Subject{get; set;} public string Body {get; set;} public virtual ICollection<EmailRecipient> EmailRecipient { get; set; } } public class EmailRecipient { public int EmaiId { get; set; } public string RecipientEmailAddress { get; set; } public int

Is it possible to tell automapper to ignore mapping at runtime?

女生的网名这么多〃 提交于 2019-12-07 15:41:11
问题 I'm using Entity Framework 6 and Automapper to map entities to dtos. I have this models public class PersonDto { public int Id { get; set; } public string Name { get; set; } public AddressDto Address { get; set; } } public class AddressDto { public int Id { get; set; } public string Street { get; set; } public string City { get; set; } } I use automapper Queryable Extension to map dto from entity. var personDto = dbContext.People.Project().To<PersonDto>(); The problem with above method is

Mapping Child Collections using AutoMapper

自古美人都是妖i 提交于 2019-12-06 13:50:13
问题 I am using Automapper for making a copy of an object My domain can be reduced into this following example Consider I have a Store with a collection of Location public class Store { public string Name { get; set;} public Person Owner {get;set;} public IList<Location> Locations { get; set;} } Below is an example of a store instance var source = new Store { Name = "Worst Buy", Owner = new Person { Name= "someone", OtherDetails= "someone" }, Locations = new List<Location> { new Location { Id = 1,

AutoMapper TwoWay Mapping with same Property Name

蹲街弑〆低调 提交于 2019-12-05 16:48:08
Given these two objects public class UserModel { public string Name {get;set;} public IList<RoleModel> Roles {get;set;} } public class UserViewModel { public string Name {get;set;} public IList<RoleViewModel> Roles {get;set;} // notice the ViewModel } Is this the most optimal way to do the mapping, or is AutoMapper capable of mapping Roles to Roles on its own? App Config Mapper.CreateMap<UserModel, UserViewModel>() .ForMember(dest => dest.Roles, opt => opt.MapFrom(src => src.Roles)); Mapper.CreateMap<UserViewModel, UserModel>() .ForMember(dest => dest.Roles, opt => opt.MapFrom(src => src.Roles

Automapper 3.0 - This type is not supported on this platform IMapperRegistry

荒凉一梦 提交于 2019-12-05 08:30:18
问题 I updated my project to use Automapper 3.0.0 and now my TFS build is not succeeding. The error is the following: " ...System.PlatformNotSupportedException: System.PlatformNotSupportedException: This type is not supported on this platform IMapperRegistry. " Is there anyone that can help me resolve this issue. In the mean time, I am going to revert to previous version since that one seems to work fine. 回答1: We had the same issue on our build server. MsTest seemed to remove DLLs it deemed

Mapping Child Collections using AutoMapper

左心房为你撑大大i 提交于 2019-12-04 18:19:40
I am using Automapper for making a copy of an object My domain can be reduced into this following example Consider I have a Store with a collection of Location public class Store { public string Name { get; set;} public Person Owner {get;set;} public IList<Location> Locations { get; set;} } Below is an example of a store instance var source = new Store { Name = "Worst Buy", Owner = new Person { Name= "someone", OtherDetails= "someone" }, Locations = new List<Location> { new Location { Id = 1, Address ="abc" }, new Location { Id = 2, Address ="abc" } } }; My Mappings are configured as var

Automapper 3.0 - This type is not supported on this platform IMapperRegistry

我的梦境 提交于 2019-12-03 22:03:16
I updated my project to use Automapper 3.0.0 and now my TFS build is not succeeding. The error is the following: " ...System.PlatformNotSupportedException: System.PlatformNotSupportedException: This type is not supported on this platform IMapperRegistry. " Is there anyone that can help me resolve this issue. In the mean time, I am going to revert to previous version since that one seems to work fine. jni We had the same issue on our build server. MsTest seemed to remove DLLs it deemed unnecessary (note : this claim is only an educated guess). To fix it, add an explicit call to something in

How to configure Auto mapper in class library project?

扶醉桌前 提交于 2019-12-03 05:36:15
问题 I am using auto mapping first time. I am working on c# application and I want to use auto mapper. (I just want to know how to use it, so I don't have asp.net app neither MVC app.) I have three class library projects. I want to write transfer process in the service project. So I want to know how and where should I configure the Auto Mapper ? 回答1: You can place the configuration anywhere: public class AutoMapperConfiguration { public static void Configure() { Mapper.Initialize(x => { x