automapper

How to use AutoMapper?

First time using AutoMapper and I'm have a hard time figuring out how to use it. I'm trying to map a ViewModel to my Database Tables. My ViewModel looks like this... public class AddressEditViewModel { public AddressEdit GetOneAddressByDistrictGuid { get; private set; } public IEnumerable<ZipCodeFind> GetZipCode...

when using Automapper, Should I flatten/map my internal objetcs of the View Model also ?

Hi all, I am using AutoMapper in my project along with, NHibernate and ASP.NET MVC 2. As the title states, if I have a list of DTOs or a DTO inside the parent DTO that I am mapping to the View Model, should I flatten out the inner DTOs as well ? Edit: Should I write view model classes for the internal objects as well or should I use ...

AutoMapper How To Map Object A To Object B Differently Depending On Context

Calling all AutoMapper gurus! I'd like to be able to map object A to object B differently depending on context at runtime. In particular, I'd like to ignore certain properties in one mapping case, and have all properties mapped in another case. What I'm experiencing is that Mapper.CreateMap can be called successfully in the different m...

Automapping to EntityKeys in Entity Framework

Does anyone have a technique to automap (using Automapper) references to child entities. So say I have a ViewModel: class AddressModel { int Id; string Street; StateModel State; } class StateModel { int Id; string Name; } And I pass this into a repository to map to equivalent entities in Entity Framework. When Aut...

AutoMapper: How to transform one-to-many into flat Dto?

If I have a one-to-many relationship and I want to transorm this into a list of flat Dto-s where some attributes of parent and some of child appear in a dto, is this something that is supported out-of-box with AutoMapper? For example if I have something like this Parent 1. ParentId 2. ParentAttr1 3. List<Child> Child 1. ChildId 2. C...

Is AutoMapper able to auto resolve types base on existing maps

I have the following code: [SetUp] public void SetMeUp() { Mapper.CreateMap<SourceObject, DestinationObject>(); } [Test] public void Testing() { var source = new SourceObject {Id = 123}; var destination1 = Mapper.Map<SourceObject, DestinationObject>(source); var destination2 = Mapper.Map<ObjectBase, ObjectBase>(sour...

AutoMapper : Site wide usage of IValueFormatter for given types

It is my understanding I can configure AutoMapper in the following way and during mapping it should format all source model dates to the rules defined in the IValueFormatter and set the result to the mapped model. ForSourceType<DateTime>().AddFormatter<StandardDateFormatter>(); ForSourceType<DateTime?>().AddFormatter<StandardDateFormat...

AutoMapper recursive

Hi! I would like to make a deep copy of a complex object tree using AutoMapper. The problem is that for each member I would like to construct a new object and then map it, and not simply copying the existing one. Here it is an example: public abstract class Test { public Test() { this.Id = Guid.NewGuid(...

AutoMapper and SecurityException in IIS

Hi everybody... I'm developing a asp.net mvc application with nhibernate and I would not like to expose my objects mappings with NHibernate, so I created DTO for each entity and I'm trying to convert my Domain objects to DTO and send it to View. So I have in my sollution: ClassLibrary with my Domain (for NHibernate) and DTO objetcs Cla...

How to configure AutoMapper if not ASP.net Application?

I'm using AutoMapper in a number of projects within my solution. These projects may be deployed independantly, across multiple servers. In the documentation for AutoMapper it says: If you're using the static Mapper method, configuration only needs to happen once per AppDomain. That means the best place to put the configurati...

Automapper: using BeforeMap and AfterMap

I am using automapper (successfully up to a point) to perform a polymorphic map between two interfaces like so: configure.CreateMap<IFrom, ITo>() .Include<FromImplementation1, ToImplementation1>() .Include<FromImplementation2, ToImplementation2>() ... ; This works fine. In addition however, the interfaces include method si...

Help making Fluent NHibernate create an oracle sequence for each table

I am using Fluent NHibernate's (1.0 RTM) automapping feature to create my oracle database schema. My issue is that all the tables are using a single "hibernate-sequence", whereas I would prefer (and my boss would demand) a sequence generator for each table. Any ideas? ...

Use Automapper to flatten sub-class of property

Given the classes: public class Person { public string Name { get; set; } } public class Student : Person { public int StudentId { get; set; } } public class Source { public Person Person { get; set; } } public class Dest { public string PersonName { get; set; } public int? PersonStudentId { get; set; } } I want...

Automapper error first time we run Unit Tests with MSTest

We are getting an Automapper error the FIRST time we run our Unit Tests in VS 2008 (MSTest). "Missing type map configuration or unsupported mapping. Exception of type 'AutoMapper.AutoMapperMappingException' was thrown" If we re-run the tests ("Run Checked Tests") then they all pass. Only 2 out of the 4 developers are having this issue. ...

can automapper create an object graph from flatted object?

Is possible with Automapper to map a flat object to complex object graph? Mapper.CreateMap<PersonDto,Person>() Map PersonDto.BirthCertificateFatherName to Person.BirthCertificate.FatherName ...

Where should 'CreateMap' statements go?

I frequently use AutoMapper to map Model (Domain) objects to ViewModel objects, which are then consumed by my Views, in a Model/View/View-Model pattern. This involves many 'Mapper.CreateMap' statements, which all must be executed, but must only be executed once in the lifecycle of the application. Technically, then, I should keep them ...

asp.net MVC 2 - View Model / Model Validation - Is there a way to map validation attributes from model to ViewModel via AutoMapper?

A short while ago I'm sure I read that is was possible to use AutoMapper to map the validation attributes from the domain model to the view model, i can't find that post any more though! Has anybody seen any code or know if it would be possible to do this? This would give the added benefit of not repeating validation in both ViewModel +...

AutoMapper Sorting List

I have this mapping defined Mapper.CreateMap<Telephone, TelephoneDTO>() .ForMember(dto => dto.Extension, opt => opt.MapFrom(src => src.Extension)) .ForMember(dto => dto.Number, opt => opt.MapFrom(src => src.Number)) .ForMember(dto => dto.Type, opt => opt.MapFrom(src => src.TelephoneType.Id)); when i do IList<TelephoneDTO> dtos = Map...

Automapper: Map an Enum to its [Description] attribute

I have a source object that looks like this: private class SourceObject { public Enum1 EnumProp1 { get; set; } public Enum2 EnumProp2 { get; set; } } The enums are decorated with a custom [Description] attribute that provides a string representation, and I have an extension method .GetDescription() that returns it. How do I ma...

With NHibernate, how can I create an INHibernateProxy?

After lots of reading about serialization, I've decided to try to create DTOs. After more reading, I decided to use AutoMapper. What I would like to do is transform the parent (easy enough) and transform the entity properties if they've been initialized, which I've done with ValueResolvers like below (I may try to make it generic once I...