automapper

AutoMapper generic mapping

时光怂恿深爱的人放手 提交于 2019-12-08 14:41:44
问题 I have searched on StackOverflow and googled about it but I havent been able to find any help or suggestion on this. I have a class like the following wich create a PagedList object and also uses AutoMappper to map types from source to destination public class PagedList<TSrc, TDest> { protected readonly List<TDest> _items = new List<TDest>(); public IEnumerable<TDest> Items { get { return this._items; } } } I would like to create a Map for this type that should convert it to another type like

Map nested elements to related lists using AutoMapper

一笑奈何 提交于 2019-12-08 14:36:25
I have two sets of objects Objects that I use in C# client application: public class EmployeeClient { public int Id { get; set; } public int DepartmentId { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string MiddleName { get; set; } } public class DepartmentClient { public int Id { get; set; } public string Name { get; set; } } public class OrganizationClient { public int Id { get; set; } public string Name { get; set; } public List<DepartmentClient> Departments { get; set; } public List<EmployeeClient> Employees { get; set; } } And DTOs: public

How to get EF POCOs from System.Data.Entities.DynamicProxies

。_饼干妹妹 提交于 2019-12-08 11:58:18
问题 My question is the same as this one However, I don't really see a solution there. Lets say I have a simple model with two POCOs, Country and State. public class Country { public string Code { get; set; } public string Name { get; set; } } public class State { public string Code { get; set; } public string Name { get; set; } public virtual Country Country { get; set; } } When I use the repository to .GetStateByCode(myCode), it retrieves a dynamic proxy object. I want to send that over the wire

How to map to class with multiple implementations using Automapper

我的未来我决定 提交于 2019-12-08 11:08:30
问题 I have configuration file in JSON format that have a list of configurations for my classes. I read configuration to BaseDTO class that have all common configurations and I would like to map those BaseDTO to specific implementations of Base class basing on field Type. Is there any way to tell automapper to use some custom mapping logic to tell it which class to create? //Map in automapper: CreateMap<BaseDTO, Base>(); public class BaseDTO { public string Type { get; set; } // rest of config

Casting/Mapping Delegates

淺唱寂寞╮ 提交于 2019-12-08 09:50:51
问题 I have a method public List<DTO.User> GetUsers(Func<Domain.User, bool> expression) { var users = new List<DTO.User>(); using(UserContext context = new UserContext()) { // obviously an error users = context.Users.ToList(); } return users; } Notice the DTO.User (a DTO) and Domain.User (a domain entity from EF) So I use AutoMapper to map entities like this public List<DTO.User> GetUsers() { var users = new List<DTO.User>(); using(UserContext context = new UserContext()) { Mapper.CreateMap<Domain

Automapper Random Errors

浪尽此生 提交于 2019-12-08 08:04:17
问题 2 months ago I have asked about this problem! and the problem still exists. I am not going to copy/paste the same problem here because I found out that the error is not for a specific Entity-DTO mapping but for any Entity-DTO which is first in a controller. I mean if the program flow hits to a Country-CountryDto, the error says: Missing type map configuration or unsupported mapping. Mapping types: Country -> CountryDTO MyApp.Domain.BoundedContext.Country -> MyApp.Application.BoundedContext

AutoMapper and Base Types

血红的双手。 提交于 2019-12-08 08:04:06
问题 I have a collection of EntityDtos. Each EntityDto has a property called EntityType. Each of these EntityTypes correspond to a different subclass, something like this abstract class EntityBase { EntityType = EntityType.Base; } class EntityOne : EntityBase { EntityType = EntityType.One; } class EntityTwo : EntityBase { EntityType = EntityType.Two; } I am trying to map to a collection of EntityBase. AutoMapper fails with the error "Instances of abstract classes cannot be created". I have the

Map nested elements to related lists using AutoMapper

狂风中的少年 提交于 2019-12-08 07:51:17
问题 I have two sets of objects Objects that I use in C# client application: public class EmployeeClient { public int Id { get; set; } public int DepartmentId { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string MiddleName { get; set; } } public class DepartmentClient { public int Id { get; set; } public string Name { get; set; } } public class OrganizationClient { public int Id { get; set; } public string Name { get; set; } public List

Map RowDataCollection to DTO using AutoMapper

倖福魔咒の 提交于 2019-12-08 07:46:47
问题 Is there a way to map a RowDataCollection to DTO using AutoMapper? Here is a scenario: DataRow to Object user.UserId = row["UserId"]; user.UserName = row["UserName"]; 回答1: glbal.asax configuration Mapper.CreateMap<DataRow, EventCompactViewModel>() .ConvertUsing(x => (EventCompactViewModel)AutomapperExtensions.DataRowMapper(x, typeof(EventCompactViewModel), null)); Data row mapper public static object DataRowMapper(DataRow dataRow, Type type, string prefix) { try { var returnObject = Activator

How to pass values to a Custom Resolver in Automapper?

十年热恋 提交于 2019-12-08 07:21:29
I need to pass values to my Custom Resolver. The values change, so I can't hard code them in my register static class. How can I achieve this? // Called from global.asa page public static void Register() { Mapper.CreateMap<Task, TaskTableViewModel>().ForMember(dest => dest.DueDate, opt => opt.ResolveUsing<DueDateResolver>().ConstructedBy(() => new DueDateResolver(dateFormatString))); } I asked about this on another board and was told it isn't possible to do in this version. 来源: https://stackoverflow.com/questions/4925044/how-to-pass-values-to-a-custom-resolver-in-automapper