automapper

AutoMapper: "Ignore the rest"?

Is there a way to tell AutoMapper to ignore all of the properties except the ones which are mapped explicitly? I have external DTO classes which are likely to change from the outside and I want to avoid specifying each property to be ignored explicitly, since adding new properties will break the functionality (cause exceptions) when tr...

AutoMapper flattens Domain Models but does it do the opposite? If not, what does?

I've been reading up on AutoMapper because of a response to one of my earlier questions here. It says that AutoMapper flattens complex domain models, but I need something that does the opposite. I need to wire up my view models (flattened domain models) to the complex domain models so that I can quickly transform a view model into a doma...

How do I do this in Unity?

Jimmy Bogart has an article on using Automapper with an IoC container. He has an example using StructureMap but I am using Unity and I'm not sure how to use an InjectionConstructor properly. Below is the code from the Article and below that is my poor attempt. Can anyone tell me how to do this properly? public class ConfigurationRegis...

How to resolve AutoMapper error? (stackoverflow exception!)

I am using AutoMapper + EF (Entities => POCO) for the following class: public class Category { public int CategoryID { get; set; } public string Name { get; set; } public Category Parent { get; set; } public IList<Category> Children { get; set; } } Since this class has relationship with itself (Parent / Children), A...

Is AutoMapper mapping EF relationships well?

I am using Entity Framework + AutoMapper to convert the EntityObjects to POCO. The relationships in EF use EntityCollection<T>. The relationships in POCO use ICollection<T>. Since EntityCollection<T> : ICollection<T>, i thought it would be super easy to cast. However, when AutoMapper tries to cast the EF EntityCollection<T> to POCO, it...

Why is AutoMapper/EF adding a new item instead of a relationship?

I have this test in my test base: public void WorksWithAreaUsers() { using (new TransactionScope()) { //arrange var userBusiness = new UserBusiness(); var user = new User { Name = "TestUser###", Login = "domain\test-user###" }; userBusiness.Add(user); var...

How do you ignore/persist values in MVC when your view-model doesn't have as many fields as your domain model?

I have a site where I'm using fluentNhibernate and Asp.net MVC. I have an Edit view that allows user to edit 8 of the 10 properties for that record (object). When you submit the form and the Model binds, the two un-editable fields come back in the view-model as Empty strings or as default DateTime values depending on the type of proper...

How to use Automapper with internal list that contains a wrapper.

Hi I struggle with AutoMapper and a list of wrappers. I have an client/server solution where on the server side the object looks like this. public class Trainer{ public List<Team> Teams{get;set;} ... } public Class Team{...} On the Client side I have my own Collection, TSCollection and the classes looks like this. public clas...

Using Automapper (.net c#) to map to a variable not in Src for use in linq2sql classes?

Hi there, I have been using automapper pretty successfully lately but i have come across a small problem for mapping the Dest to a variable not a available in the Src.... An example explains it better.. basically i am mapping from dest to src as per instructions .. all working well but i need to now map a destination to a variable named...

Issues with Fluent Nhibernate Automapping in version 1.0RC

I am new to NHibernate and am running into some issues getting the Automap functionality to work properly. Here are a couple of issues I am having. The getting started wiki for Fluent NHibernate (http://wiki.fluentnhibernate.org/Getting_started) defines a sample with store, product, and employee classes--as well as the mapping for thos...

How can you create Clustered Indexes with Fluent NHibernate?

I am using Fluent-NHibernate (with automapping) to generate my tables but would like to choose a different clustered index than the ID field which is used by default. How can you create clustered indexes with Fluent NHibernate on a field other than the default Primary Key field? The primary reasoning behind this is simple. I am using Gu...

Issue With Fluent Nhibernate Automapping and Guids / UniqueIdentifiers as Primary Key Fields

I am attempting to use the Fluent-NHibernate automapping functionality (in the latest version of the software) and am running into problems using Guids as the Primary Key fields. If I use integer fields for the primary keys, the tables are generated successfully and all Nhibernate functionality seems to work fine. FYI, I am using NHibern...

Is automapper case sensitive or insensitive?

if object a has a property name 'Id' and object b has a property name 'ID' will AutoMapper correctly map the 2 properties (without doing a .ForMember(...) call)? ...

Automapper or Otis: Mapping ReadonlyDictionary <name, value> to a DTO's IList<string>

I am trying out Automapper as well as otis. I have a source type that is something list this (only partial code shown here): class Source { ReadOnlyDictionary<string, customtype> items; } My DTO is like so: class ClassDTO { IList<string> pageNames; } Now how do I map the pagenames in my DTO to "items" in the source type, ...

How do I turn off AutoMapper auto-list conversion between List<T> and EntitySet<T> ?

I'm mapping my Linq-To-SQL generated entities to DTOs using AutoMapper. When I initially created the unit tests, I had specific maps (through a static configuration class) set up to convert one type of EntitySet to a generic List (and vice-versa) Mapper.CreateMap<EntitySet<Member>, List<MemberDTO>>(); Mapper.CreateMap<List<MemberDTO>...

How to Configure AutoMapper Once Per AppDomain

My current project with assemblies for the domain model, MVC web application, and unit tests. How can I set up the AutoMapper configuration so that all assemblies reference the same configuration? I would guess that I could put items in Global.asax for the web app, but how can I use that in the unit tests? Also, if the config is in Glo...

AutoMapper - setting destination string to null actually makes it string.Empty

With the following mapping: Mapper.CreateMap<ObjectA, ObjectB>() .ForMember(dest => dest.SomeStringProperty, opt => opt.MapFrom(src => null)) SomeStringProperty is now empty string not null (as I would expect) Is this a bug? How can I get it to actually be null? I see that opt.Ignore() will make it null but I actually want to do...

Problem Using AutoMapper To Map DAL Properties To BLL Properties

I have a BLL class which contains properties for the fields in a Country table (CountryCode, CountryName, etc). It also has a property ioDAL, which is a reference to a DAL class (created with SubSonic 2.2), which has same named fields. I have a LoadRecord() method which calls the DAL's FetchById() method that populates the DAL properti...

Automapper - Nested entities

I'm updating or creating an entity that has a child relationship, say the aggregate root is Product (ProductId, Title) which has zero or more ProductSuppliers (ProductSupplierId, SuppliedAtPrice, SupplierInfoId), and the DTO represents a similar structure (all the info). Simple enough. I've created a simple map for ProductDTO and Produc...

Complex Model updating in form posting scenarios and MVC

Many people have written about using Automapper to map domain objects (models) to view models, which I find very interesting and useful, but my question is about how to do the opposite. I understand the complexity of this process and why Automapper doesn't work in that scenario but I have to do that a lot with form posting, specially whe...