automapper

ASP.NET MVC2 Posting a ViewModel mapping to Domain (LINQ) to Submitting changes

I'm using AutoMapper to map between a Linq Domain object and a ViewModel to display an Edit Form to the user which works perfectly. When they click submit I'd like to know the best way to map the ViewModel back to a Linq entity and persist it to the database. The Linq entity I'm using has multiple collections of other entities (ie one-...

AutoMapper and inheritance - How to Map?

Hi! Have this scenario: Public class Base { public string Name; } Public Class ClassA :Base { public int32 Number; } Public Class ClassB :Base { Public string Description;} Public Class DTO { public string Name; public int32 Number; Public string Description; } I have an IList<Base> my maps are: AutoMapper.Mapper.Crea...

Is there a python implementation to .net automapper?

Automapper is a object-object mapper where we can use to project domain model to view model in asp.net mvc. http://automapper.codeplex.com/ Is there equivalent implementation in Python for use in Django(Template)/Pylons ? Or is there necessity for this in Python world? ...

Add another propertymapping? (AutoMapper)

Can you Mapper.CreateMap<Foo, Bar>() .ForMember(x => x.IsFoo, x => x.Ignore()); and then later on add another mapping of the sort .ForMember(x => x.IsBar, x => x.Ignore()); or even change the old one .ForMember(x => x.IsFor, x => x.MapFrom(z => z.IsBar)); ? If so, how? ...

Automapper: Formatter for Interface Property

If I have some classes that implement the same interface, so they all contain the same property. Is there a way to add a formatter to these properties? I only found the possibility to add a formatter to a specific property type. Here's some code that should clarify what I mean: public interface ITaggable { IList<string> Tags { get;...

Automapper, mapping IEnumearble<Foo> to IEnumearble<FooDto>

Hi there: I ve been trying to do something like this: ... Mapper.CreateMap<IEnumerable<Foo>, IEnumerable<FooDto>>(); var fooDtos = Mapper.Map<IEnumerable<Foo>, IEnumerable<FooDto>>(foos); Keep in mind that Foo is an entity but the properties are exactly the same that FooDto. The Result of fooDtos is an empty enumerable Tips? ...

Is it possible to map object to a List in Automapper?

I have a class Foos: public class Foos { public string TypeName; public IEnumerable<int> IDs; } Is it possible to map it with AutoMapper to IList of Foo objects? public class Foo { public string TypeName; public int ID; } ...

How to deep clone objects containing an IList property using AutoMapper

I am trying to deep clone the following class using AutoMapper: public class MainData { public MainData() { Details = new List<Detail>(); } public int Id { get; private set; } public DateTime LastUpdate { get; private set; } public IList<Detail> Details { get; private set; } public int Prop1 { get; s...

How to configure Automapper to be injected with Ninject 2.0?

There are configuration examples for Structure Map and Windsor: http://www.cprieto.com/index.php/2009/08/20/using-automapper-with-castle-windsor/ But I haven't found anything for Ninject. Do you know how to translate those mappings to Ninject? ...

How to find the source property based on the name of a flattened property with AutoMapper

I'm using AutoMapper and I'd like it to trace back a source property based on the name of the mapped (flattened) destination property. This is because my MVC controller has the name of a mapped property that it needs to provide to a service call that for sorting purposes. The service needs to know the name of the property that the mappi...

AutoMapper: create instance of destination type if source == null

Is it possible to configure AutoMapper to return a new instance of the destination type if the source object is null? Source source = null; Dest d1 = AutoMapper.Mapper.Map<Source, Dest>(source); // d1 == null // I'm looking for a way to configure AutoMapper to // eliminate this code: Dest d2 = AutoMapper.Mapper.Map<Source, Dest>(source...

How to Perform String Lookups in Automapper Based on Destination Property Name?

I'd like to generalize a property lookup from code like this .ForMember(dest => dest.FirstName, opt => opt.MapFrom(src => src.GetValue("FirstName")) .ForMember(dest => dest.LastName, opt => opt.MapFrom(src => src.GetValue("LastName")) ... (repeated for many properties) to a one-liner, conceptually something like this: // How can I ac...

Automapper : mapping issue with inheritance and abstract base class on collections with Entity Framework 4 Proxy Pocos

I am having an issue using AutoMapper (which is an excellent technology) to map a business object to a DTO where I have inheritance off of an abstract base class within a collection. Here are my objects: abstract class Payment class CashPayment : Payment class CreditCardPayment : Payment I also have an invoice object which contains a...

AutoMapper limit depth of mapping or map lazily

Hello, AutoMapper is great, saves a lot of time, but when I started looking at the performance of my application AutoMapper is responsible for performance loss. I'm using lazy loading with NHibernate. Most of the time a need parent entity without needing to access child entities at all. In reality what happens is that AutoMapper tries ...

AutoMapper: User Specific Mapping

I have a SearchService with a Search() method that retrieves an IEnumerable<Search> from a repository. These Search objects come directly from LINQ To SQL. Next I'm using AutoMapper to convert those Search types into SearchModel types (and later they get passed into a controller, for example). var searches = searchRepository.GetByUserID...

AutoMapper strings to enum descriptions

Given the requirement: Take an object graph, set all enum type properties based on the processed value of a second string property. Convention dictates that the name of the source string property will be that of the enum property with a postfix of "Raw". By processed we mean we'll need to strip specified characters e.t.c. I've looked...

Mapping from list down to object with AutoMapper

I'm new with AutoMapper and have a problem I'm trying to solve. If I have a source class like this: public class Membership { public int MembershipId { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string OrganizationName { get; set; } public List<Address> Addresses { ...

AutoMapper -- how to manipulate all values of a given type during mapping?

Quick question regarding Automapper. I'm mapping data from an incoming web service, where datetimes fields are not null, but sometimes have the value of DateTime.MinValue as a work-around (I don't own this service so I'm at their mercy I'm afraid). I'm mapping from those objects to Linq To Sql objects created off of a db model I create...

Resolve Array with Ninject

In Ninject there's automatic implicit self-binding for concrete types. So without further configuration I can resolve every type in my application, like: Foo foo = Kernel.Get(typeof(Foo)); Now if I need an Array of Foo, how would I do that? Foo[] foos = Kernel.Get(typeof(Foo[])); // does not work EDIT: For clarification, here is, ...

How to get data for a dropdownlist into viewmodel when using AutoMapper/AutoMapViewResult

After reading ASP.NET MVC 2 in Action and watching Jimmy Bogard's presentation from MvcConf (both highly recommended!), I began to implement some of their ideas. One of the cool things they do, is not only to use AutoMapper to map your entities to some viewmodel, but automate this with an AutoMapViewResult: public class EventsControlle...