automapper

NHibernate one-to-many delete

I am working on an ASP.NET MVC application using NHibernate as the ORM. I have two domain objects: public class Contact { public int ID { get; set } public string Name { get;set; } public IList<ContactNumber> ContactNumbers { get; set; } } public class ContactNumber { p...

C# coercion operator?

I got this test: [Fact] public void EverythingIsMappedJustFine(){ new AutoMapperTask().Execute(); Mapper.AssertConfigurationIsValid(); } It throws a bit strange exception: Test 'Unit.Web.Bootstrap.AutoMapperFacts.EverythingIsMappedJustFine' failed: System.InvalidOperationException : No coercion operator is defined betwee...

Complex DAL -> BL mappings using AutoMapper

I'm considering to use AutoMapper in the upcoming project and trying to find possible "bottlenecks". At the moment the most complex case i can imagine is the following: A domain class which is represented by 3 (for example) tables in the database (my data access layer is LINQ to SQL). To build an instance of the class i need to perform 3...

DTO shape: flat, complex/nested, or a mixture of both

I have an MVC2 n-tier application (DAL, Domain, Service, MVC web) using a DDD approach (Domain Driven Design), having a Domain Model with repositories. My service layer uses a Request/Response pattern, in which the Request and Response objects contain DTO's (Data Transfer Objects) to marshal data from one layer to the next, and the mapp...

AutoMapper ignores Properties

Hi, when I'm using this mapping Mapper.CreateMap<DataSourceConfigurationContract, DataSourceConfigurationContract>().ForMember(x => (object)x.DatabaseTypeException, opt => opt.Ignore()) .ForMember(x => (object)x.DatabaseType, opt =...

Map Func<Type1, bool> to Func<Type2, bool>

I'm using Entity Framework behind a set of repositories. The repositories use DTOs instead of the entity objects generated by the Entity Framework. I'm using AutoMapper to convert them back and forth. I'm having trouble figuring out how to do the following: Method definition: public IEnumerable<DTO.User> Get(Func<DTO.User, bool> where...

How to map poco to JSON using Automapper

In my MVC 2 application I have a typical method that calls a web service, builds a JSON data object and returns it to the view. Everything works fine, but I was wondering if there is a way to do the mapping with Automapper so I can remove the ugly code from my controller. Thanks in advance Here is my Action method public virtual Actio...

How to specify a specific type converter for a given property using AutoMapper

How can I override the type converter being used by AutoMapper for a given property? For example, if I have: public class Foo { public string Name { get; set; } } public class Bar { public string Name { get; set; } } Now I simply want to map Foo.Name to Bar.Name but using a specified type converter. I see how I can do it usi...

Is there anything similar to AutoMapper for Objective-c?

AutoMapper for .Net lets you map from one type to another. Its most basic function is to create one type of class from another type of class by copying property values from type A that exist in type B (have matching names and types). Example: public class ClassA { public string StringProp { get; set; } public int IntProp { get...

What are the advantages of using automapper?

Hey all, My question might be silly, but I'm pretty sure I miss a very important part of the issue. I have to do some object to object mapping (between domain classes used in C# project and classes which are sent to flash clients). My first choice was Automapper. But Ive had some issues with it (nested properties, not paramterless cons...

How would a LISP developer solve the problem that AutoMapper solves in .NET?

I.e. transferring the state from one object to another object, which shares some (but not all) of the first object's members. I'm not applying this question to any real-life problem yet, but I guess I'm asking it to get a feel for the differences between the problem-solving approach in LISP as opposed to object-oriented languages like C...

Automapper: Is there a built-in way to map a condition from the source object to a boolean on the target?

I just threw together a custom AutoMapper ValueResolver to try to map a condition from my domain object to a boolean property on an MVC view model, and it's so simple that I have a feeling there has to be a built-in way to do what I'm trying to do without a custom resolver. The logic that I'm trying to implement is that if "MyDomainObje...

C# code to create AutoMapper DDL values (text,value) from *any* Domain Model Object, providing the two field names in the parameters

What would the C# code be to create a (service) method to return an object (ViewModel for DDL) using AutoMapper and provide the two field names as parameters? DDL is for a Drop Down List: public class DDLitems { public string text {get;set;} public string value {get;set} } My horrible pseudo C# code idea: (yea no idea how to ...

C# Function that accepts string parameters: How to refactor to use something strongly typed?

I have this C# code that works just fine, which grabs any two fields and puts them in a list for a Drop Down List: var myDDL = GetDDLValues<Product>( myContact, "contactid", "companyname"); I would like it to take the two string parameters in something other than strings. This would be really nice to do: GetDDLValues<Product>( myCon...

Can automapper handle a case where the some of the properties do not match?

Suppose I have a destination class and a source class that are mostly the same. Almost all of the properties map automatically using automapper. Say that of the 30 properties on these classes, two don't have a direct corelation in any way that automapper can automatically figureout. Is there a way to tell automapper to connect two pro...

Can automapper be told that a property is ok to be left blank?

I am trying to decide if I want to pursue Automapper as a technology to use at my company. Before I dig in, I have a question that I want to be sure is doable with automapper. Say I have a property in my destination class that I don't want to fill with automapper. Is there a way to tell automapper to ignore the property and not fail w...

automapper how to ignore property in source item that does not exist in destination

I have a Linq to Sql source being mapped to a DTO. The src contains a property which does not exist in the DTO. I.e. src.State exists but dest.State does not exist. This causes the Mapping Configuration to throw a ConfigurationException. I don't want to add the property to the DTO (e.g. dest.State) to make it work and the .ForMember...