automapper-2

Am I using Automapper 2.0's Include functionality correctly?

陌路散爱 提交于 2019-12-10 03:15:09
问题 Either I'm not, or it isn't working... I have a single Source class that I want to map to multiple views that inherit from each other. Basically the base class is the Detail, and the child class is Edit or Update which use all the same data as Detail, plus a couple other fields to manage their own lists or whatever. Here are the maps I'm using: Mapper.CreateMap<Ticket, Detail>() .Include<Ticket, Update>() .Include<Ticket, Edit>() .ForMember(dest => dest.Priority, opt => opt.MapFrom(src => src

Automapper map from one object to nested objects

空扰寡人 提交于 2019-12-07 03:28:48
问题 What is the best way to map inner objects with Automapper 2.0 Use the solution in this question (Automapper 1.0) Create a Custom Value Resolvers ? public class DTOObject { // MainObject public int Id { get; set; } public string Name { get; set; } // SubObject (TopObject) public string TopText { get; set; } public string TopFont { get; set; } // SubObject (BottomObject) public string BottomText { get; set; } public string BottomFont { get; set; } } public class MainObject { public int Id { get

Projection using contextual values in AutoMapper

折月煮酒 提交于 2019-12-07 01:47:09
问题 I'm currently evaluation whether AutoMapper can be of benefit to our project. I'm working on a RESTful Web API using ASP.NET Web API, and one of the things I must return is a resource that contains links. Consider this simplified example, using the following domain object: public class Customer { public string Name { get; set; } } I need to map this into a resource object, sort of like a DTO but with added properties to facilitate REST. This is what my resource object may look like: public

AutoMapper - Why it is overwriting whole object? [duplicate]

余生长醉 提交于 2019-12-05 20:32:23
This question already has an answer here: Automapper: Update property values without creating a new object 3 answers I don't understand why it's overwriting my whole object. The reason is that I get my User object from db an I want to assign new values from DTO. Instead of just adding those new values it's creating new object that has new values but all previous are set to null . How can I make sure that in this case he will "upgrade" my object, not create new one? Scenario /users/{id} - PUT // User has id, username, fullname // UserPut has fullname public HttpResponseMessage Put(int id,

Automapper map from one object to nested objects

ⅰ亾dé卋堺 提交于 2019-12-05 12:58:25
What is the best way to map inner objects with Automapper 2.0 Use the solution in this question (Automapper 1.0) Create a Custom Value Resolvers ? public class DTOObject { // MainObject public int Id { get; set; } public string Name { get; set; } // SubObject (TopObject) public string TopText { get; set; } public string TopFont { get; set; } // SubObject (BottomObject) public string BottomText { get; set; } public string BottomFont { get; set; } } public class MainObject { public int Id { get; set; } public string Name { get; set; } public SubObject TopObject { get; set; } public SubObject

Projection using contextual values in AutoMapper

半城伤御伤魂 提交于 2019-12-05 05:20:01
I'm currently evaluation whether AutoMapper can be of benefit to our project. I'm working on a RESTful Web API using ASP.NET Web API, and one of the things I must return is a resource that contains links. Consider this simplified example, using the following domain object: public class Customer { public string Name { get; set; } } I need to map this into a resource object, sort of like a DTO but with added properties to facilitate REST. This is what my resource object may look like: public class CustomerResource { public string Name { get; set; } public Dictionary<string, string> Links { get;

Random “Missing type map configuration or unsupported mapping.” Error in Automapper

混江龙づ霸主 提交于 2019-12-04 06:11:32
问题 Please see this post for the solution. Ok, I finally figured it out. The: AppDomain.CurrentDomain.GetAssemblies() piece of my code sometimes does not get my mapping assembly so while it is missing I get an error. Replacing this code by forcing the app to find all assemblies solved my problem. My Entity: /// <summary> /// Get/Set the name of the Country /// </summary> public string CountryName { get; set; } /// <summary> /// Get/Set the international code of the Country /// </summary> public

Mapping one source class to multiple derived classes with automapper

你说的曾经没有我的故事 提交于 2019-12-03 08:35:27
问题 Suppose i have a source class: public class Source { //Several properties that can be mapped to DerivedBase and its subclasses } And some destination classes: public class DestinationBase { //Several properties } public class DestinationDerived1 : DestinationBase { //Several properties } public class DestinationDerived2 : DestinationBase { //Several properties } Then I wish the derived destination classes to inherit the automapper configuration of the baseclass because I do not want to have

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

Mapping one source class to multiple derived classes with automapper

[亡魂溺海] 提交于 2019-12-02 22:21:18
Suppose i have a source class: public class Source { //Several properties that can be mapped to DerivedBase and its subclasses } And some destination classes: public class DestinationBase { //Several properties } public class DestinationDerived1 : DestinationBase { //Several properties } public class DestinationDerived2 : DestinationBase { //Several properties } Then I wish the derived destination classes to inherit the automapper configuration of the baseclass because I do not want to have to repeat it, is there any way to achieve this? Mapper.CreateMap<Source, DestinationBase>() .ForMember(.