automapper-2

AutoMapper and flattening nested arrays

一笑奈何 提交于 2019-11-28 07:47:48
I'm trying to use AutoMapper to flatten multiple levels of arrays. Consider the following source classes: class X { public string A { get; set; } public Y[] B { get; set; } } class Y { public string C { get; set; } public Z[] D { get; set; } } class Z { public string E { get; set; } public string F { get; set; } } And the following destination: class Destination { public string A { get; set; } public string C { get; set; } public string E { get; set; } public string F { get; set; } } What I'd like to be able to do is get a List from one or more X, e.g.: Mapper.Map<IEnumerable<X>, IEnumerable

Automapper expression must resolve to top-level member

北战南征 提交于 2019-11-27 23:02:27
问题 I am using automapper to map source and destination objects. While I map them I get the below error. Expression must resolve to top-level member. Parameter name: lambdaExpression I am not able resolve the issue. My source and destination objects are: public partial class Source { private Car[] cars; public Car[] Cars { get { return this.cars; } set { this.cars = value; } } } public partial class Destination { private OutputData output; public OutputData Output { get { return this.output; }

How to configure Conditional Mapping in AutoMapper?

做~自己de王妃 提交于 2019-11-27 12:42:09
问题 Suppose I have the following entities (classes) public class Target { public string Value; } public class Source { public string Value1; public string Value2; } Now I want to configure Auto Map, to Map Value1 to Value if Value1 starts with "A", but otherwise I want to map Value2 to Value. This is what I have so far: Mapper .CreateMap<Source,Target>() .ForMember(t => t.Value, o => { o.Condition(s => s.Value1.StartsWith("A")); o.MapFrom(s => s.Value1); <<***But then how do I supply the negative

Circular reference causing stack overflow with Automapper

跟風遠走 提交于 2019-11-27 05:03:39
I'm using Automapper to map my NHibernate proxy objects (DTO) to my CSLA business objects I'm using Fluent NHibernate to create the mappings - this is working fine The problem I have is that the Order has a collection of OrderLines and each of these has a reference to Order . public class OrderMapping : ClassMap<OrderDTO> { public OrderMapping() { // Standard properties Id(x => x.OrderId); Map(x => x.OrderDate); Map(x => x.Address); HasMany<OrderLineDTO>(x => x.OrderLines).KeyColumn("OrderId").Inverse(); Table("`Order`"); } } public class OrderDTO { // Standard properties public virtual int

AutoMapper: What is the difference between MapFrom and ResolveUsing?

大兔子大兔子 提交于 2019-11-27 04:27:29
Ignoring the ResolveUsing overloads that take an IValueResolver, and looking only at these 2 methods: void ResolveUsing(Func<TSource, object> resolver); void MapFrom<TMember>(Expression<Func<TSource, TMember>> sourceMember); The main difference between these 2 seems to be that ResolveUsing takes a Func<TSource, object> , whereas MapFrom takes an Expression<Func<TSource, TMember>> . However in client code that actually uses one of these methods with a lambda expression, they seem to be interchangeable: Mapper.CreateMap<SourceType, DestType>() // uses ResolveUsing .ForMember(d => d.DestPropX, o

Circular reference causing stack overflow with Automapper

China☆狼群 提交于 2019-11-26 11:25:55
问题 I\'m using Automapper to map my NHibernate proxy objects (DTO) to my CSLA business objects I\'m using Fluent NHibernate to create the mappings - this is working fine The problem I have is that the Order has a collection of OrderLines and each of these has a reference to Order . public class OrderMapping : ClassMap<OrderDTO> { public OrderMapping() { // Standard properties Id(x => x.OrderId); Map(x => x.OrderDate); Map(x => x.Address); HasMany<OrderLineDTO>(x => x.OrderLines).KeyColumn(\