Where to implement Automapper in a DDD + layered architecture

To answer your specific question I will speak more generally about your architecture. The architecture you’ve devised for your project is subtly different from a typical architecture used with DDD. While the way you’ve partitioned responsibilities is typical, in DDD, domain classes aren’t responsible for their own persistence. In fact a mantra of DDD is … Read more

A better way to use AutoMapper to flatten nested objects?

I much prefer avoiding the older Static methods and do it like this. Place our mapping definitions into a Profile. We map the Root first, and then apply the mappings of the Nested afterwards. Note the use of the Context. public class MappingProfile : Profile { public MappingProfile() { CreateMap<Root, Flattened>() .AfterMap((src, dest, context) => … Read more

Mapping collections using AutoMapper

You don’t need to setup your mapping for collections, just the element types. So just: Mapper.CreateMap<X, Y>(); Mapper.Map<X[], Collection<Y>>(objectToMap); See here for more info: http://automapper.codeplex.com/wikipage?title=Lists%20and%20Arrays&referringTitle=Home

How to handle custom Properties in AutoMapper

On automapper where you create the Map you can specify additional processes for specific members of the destination type. So where your default map would be Mapper.Map<Domain.User, UsersDetailsViewModel>(); there is a fluent syntax to define the more complicated mappings: Mapper.Map<Domain.User, UsersDetailsViewModel>() .ForMember(vm=>vm.UserName, m=>m.MapFrom(u=>(u.UserName != null) ? u.UserName : “User” + u.ID.ToString())); Here the ForMember takes … Read more

Automapper expression must resolve to top-level member

You are using : Mapper.CreateMap<Source, Destination>() .ForMember( dest => dest.OutputData.Cars, input => input.MapFrom(i => i.Cars)); This won’t work because you are using 2 level in the dest lambda. With Automapper, you can only map to 1 level. To fix the problem you need to use a single level : Mapper.CreateMap<Source, Destination>() .ForMember( dest => dest.OutputData, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)