automapper

delegating Member mapping to child object with AutoMapper

て烟熏妆下的殇ゞ 提交于 2019-12-11 07:33:12
问题 I have a destination class that combines properties from a source class and an inner class of that source class. class Source { public int Id {get;set;} public int UseThisInt {get;set;} public InnerType Inner {get;set;} // other properties that the Destination class is not interested in } class InnerType { public int Id {get;set;} public int Height {get;set;} // more inner properties } my destination class should combine UseThisInt and all properties of the InnerType . class Destination {

Automapper - Map objects with IEnumerable<anotherType>

懵懂的女人 提交于 2019-12-11 07:17:52
问题 SOLVED: I had a property defined incorrectly! I'm getting this error... Missing type map configuration or unsupported mapping. Mapping types: HouseDomain -> RoomDomain {namespace}.HouseDomain -> {namespace}.RoomDomain Destination path: City.Houses.Houses.Houses0[0] So for example, I have public class CityDomain { public IEnumerable<HouseDomain> DomainHouses {get;set;} } public class HouseDomain { public IEnumerable<RoomDomain> DomainRooms {get;set;} } public class RoomDomain { //whatever }

automapper unflatten excludes value from parent object

試著忘記壹切 提交于 2019-12-11 07:06:24
问题 I've a situation where entity framework core (2.0) is performing additional work to a parent table when I update a row in a child table. I've pin-pointed the cause to a value not being set in the unflattened object tree produced by AutoMapper (I'm not saying it is an error in AutoMapper; it's probably more to do with my code). I'm using ASP.NET Core 2.0, C#, EF Core 2.0 and AutoMapper for the API development side. The database already exists and the EF classes scaffolded from it. To keep it

AutoMapper doesn't ignore nested types

﹥>﹥吖頭↗ 提交于 2019-12-11 07:03:36
问题 I have a situation where AutoMapper doesn't work properly with ignoring members. Here is the class structure and mappings. public class Class1 { public Class2 Class2 { get; set; } } public class Class2 { public List<Class3> class3List { get; set; } } Mapper.CreateMap<Class1, Class1>(); Mapper.CreateMap<Class2, Class2> .ForMember(dest => dest.class3List, opt => opt.Ignore()); Mapper.CreateMap<Class3, Class3>(); And when I map Class1 to Class1 Mapper.Map<Class1, Class1>(object1, object2); In

WPF Prism application - Automapper causes System.Core load failure

孤街浪徒 提交于 2019-12-11 06:47:58
问题 I have a WPF 4.5 Prism project which works fine until I add Automapper 3.0 to it. When I add Automapper to my DAL in order to translate from Entity Framework objects to DTOs, the application fails in runtime, seemingly immediately after shell creation. I read somewhere that Automapper isn't completely deployed in some cases, so I have added references to Automapper and Automapper.Net4 to the Shell project as well to make sure everything is deployed. This is the error message I get: Could not

Automapper: List to members

China☆狼群 提交于 2019-12-11 06:25:16
问题 I'd like to map an arbitrary list of abstract types to an arbitrary set of properties, that share the same base type. Here is some UnitTest code, which currently fails and which I want to success. Could you help me, get a generic solution? Here are the classes: public class Source { public string Name { get; set; } = "SomeName"; public Dictionary<string, ValueType> SourceList { get; set; } = new Dictionary<string, ValueType>(); } public interface IDestination { string Name { get; set; } }

AutoMapper mapping int[] or List<int> from ViewModel to a List<Type> in Domain Model

浪子不回头ぞ 提交于 2019-12-11 06:18:40
问题 I'm new to AutoMapper and I've been reading and reading questions around here but I'm not quite able to figure out what looks like a very trivial question. First my classes, then the question(s): GatewayModel.cs public class Gateway { public int GatewayID { get; set; } public List<Category> Categories { get; set; } public ContentType ContentType { get; set; } // ... } public class Category { public int ID { get; set; } public int Name { get; set; } public Category() { } public Category( int

Automapper mapping function

佐手、 提交于 2019-12-11 06:06:39
问题 Hello everyone I am trying to achieve something relatively simple in Automapper but I keep on failing. I am trying to map a property on my Dto with a function expression .ForMember(dest => dest.HasPaid, opt => opt.MapFrom(c => MapHasPaid(c))) private bool MapHasPaid(AppUser src) { var lastPayment = src.RentPayments.OrderByDescending(p => p.DateTo).FirstOrDefault(); if (lastPayment == null) { return false; } return lastPayment.DateFrom.Date <= DateTime.Now.Date && DateTime.Now.Date <=

Automapper to update an existing object as opposed to creating a new one [duplicate]

烂漫一生 提交于 2019-12-11 05:14:54
问题 This question already has answers here : Automapper: Update property values without creating a new object (3 answers) Closed last year . Is there any way to use Automapper 5.1.1 to update an existing object as opposed to creating a new one. For example we have a Customer entity and a CustomerViewModel . We would like to update an existing Customer with the CustomerViewModel field values. Would greatly appreciate your assistance. 回答1: It is not adviced to use Automapper to map a model to your

AutoMapper: Losing unmapped property values when mapping Child Collection 1 to Child Collection2

ぐ巨炮叔叔 提交于 2019-12-11 04:29:30
问题 Using AutoMapper: When mapping nested collections, I expect any unmapped properties to have their original values retained. Instead, they are being set to null. Example: I have these four classes (note that Test2Child has the Name property, while Test1Child does not): public class Test1 { public List<Test1Child> Children { get; set; } } public class Test2 { public List<Test2Child> Children { get; set; } } public class Test1Child { public int Value { get; set; } } public class Test2Child {