automapper

AutoMapper a viable alternative to two way databinding using a FormView?

I've started using the FormView control to enable two way databinding in asp.net webforms. I liked that it saved me the trouble of writing loadForm and unloadForm routines on every page. So it seemed to work nicely at the start when I was just using textboxes everywhere....but when it came time to start converting some to DropDownLists...

Can Automapper populate a strongly typed object from the data in a NameValueCollection?

Can Automapper map values from a NameValueCollection onto an object, where target.Foo receives the value stored in the collection under the "Foo" key? I have a business object that stores some data in named properties and other data in a property bag. Different views make different assumptions about the data in the property bag, which ...

In which order is model binding and validation done in ASP.NET MVC 2?

I am using ASP.NET MVC 2, and am using a view-model per view approach. I am also using Automapper to map properties from my domain-model to the view-model. Take this example view-model (with Required data annotation attributes for validation purposes): public class BlogPost_ViewModel { public int Id { get; set; } [Required] ...

Automapper -cannot resolve the Generic List

Mapper.CreateMap<BusinessObject, Proxy.DataContacts.DCObject>() .ForMember(x => x.ExtensionData, y => y.Ignore()) .ForMember(z => z.ValidPlaces, a=> a.ResolveUsing(typeof(ValidPlaces))); Mapper.AssertConfigurationIsValid(); proxydcObject = Mapper.Map<BusinessObject, Proxy.DataContracts.DCObject>(_instanceOfBusinessObject); //thro...

AutoMapper - Intercept member mapping for each member

Is there a way to intercept the mapping of each property? What I would really like to do is something like ForAllMembers(opt => opt.Ignore(Func); My ultimate goal is to implement column permission checking. But I want an opt in strategy such that all fail unless secured, and I do not want to have to touch my mapping configuration if...

AutoMapper map IdPost to Post

I'm trying to map int IdPost on DTO to Post object on Blog object, based on a rule. I would like to achieve this: BlogDTO.IdPost => Blog.Post Post would be loaded by NHibernate: Session.Load(IdPost) How can I achieve this with AutoMapper? ...

Approaches to use Repositories (w/ StructureMap) with AutoMapper?

Any idea how I can tell AutoMapper to resolve a TypeConverter constructor argument using StructureMap? ie. We have this: private class StringIdToContentProviderConverter : TypeConverter<string, ContentProvider> { private readonly IContentProviderRepository _repository; public StringIdToContentProviderConverter(ICon...

Can AutoMapper select a value T from a child collection into a new list<T>?

I have an object like this: public class Foo { public string Title { get; set; } public IList<FooChild> Children { get; set; } } public class FooChild { public string Title { get; set; } } I want to map this onto a view model like this: public class FooDTO { public string Title { get; set; } public List<string> C...

AutoMapper index out of bounds exception in MappingEngine.cs

Currently we are running AutoMapper 1.0.1.156 in production on a WCF webservice and after about a week or so we will start to get the following error (note this was also happening in 0.4.0.126 but we couldn't get a stack trace because we only had the .dll from codeplex and no .pdb): Trying to map DataAccess.Call to DataTypes.Call. ...

Automapper Type Converter from String to IEnumerable<String> is not being called

Here is my custom Type Converter. public class StringListTypeConverter : TypeConverter<String, IEnumerable<String>> { protected override IEnumerable<string> ConvertCore(String source) { if (source == null) yield break; foreach (var item in source.Split(',')) yield return item.Trim(); ...

Automapper use in a MVVM application

I am building a MVVM application. The model / entity (I am using NHibernate) is already done, and I am thinking of using AutoMapper to map between the ViewModel and Model. However this clause scares the jebus out of me: (from http://www.lostechies.com/blogs/jimmy_bogard/archive/2009/01/22/automapper-the-object-object-mapper.aspx) Bl...

Can AutoMapper call a method on destination for each member of collection on source?

I have two classes as below. public class Destination { public Destination() { _StringCollection = new List<String>(); } private ICollection<String> _StringCollection; public IEnumerable<String> StringCollection { get { return _StringCollection.AsEnumerable<String>(); } } public void ...

AutoMapper How to map nested object from an ObjectId

I am trying to map the ReferralContract.AssessmentId property to Referral.Assessment.Id The below code works but I am sure that there is a cleaner way to do.... Please tell me this is so ;-) // Destination classes public class Referral { public Referral() { Assessment = new Assessment(); } public int Id { get; ...

BestPractice: Pros and Cons for using AutoMapper or LINQ (LINQ to Objects) for mapping between a Domain Model and a Presentation Model

What do you think? How do you map between your domain and presentation model? ...

Automapper failing to map on IEnumerable

I have two classes like so: public class SentEmailAttachment : ISentEmailAttachment { public SentEmailAttachment(); public string FileName { get; set; } public string ID { get; set; } public string SentEmailID { get; set; } public string StorageService { get; set; } public string StorageServiceFileID { get; set;...

Using AutoMapper to dynamically map objects including arrays

I'm trying to build a way of mapping from one type to another, knwoing they will (should) have the same structure. Related Question. For ease of the fiddly bits, I'm using AutoMapper from Codeplex, with the following function: private static List<Type> seenTypes = new List<Type>(); private static void MapDataObjects(Type a, Type b) { ...

How to scan and auto-configure profiles in AutoMapper?

Is there any way to auto-configue Automapper to scan for all profiles in namespace/assembly? What I would like to do is to add mapping profiles to AutoMapper from given assembly filtered by given interface, something like Scan Conventions in StructureMap: public static void Configure() { ObjectFactory.Initialize(x => ...

Automapper - ignoring while mapping

Is it possible to ignore depending on destination value? look what i want to do: object c; var key = ce.CreateEntityKey<CustomerDataContract, Customer>("FullCustomerSet", item, o => o.ID); if (ce.TryGetObjectByKey(key, out c)) { Mapper.Map(item, (Customer)c); } else { c = Mapper.Map<CustomerDataContract...

AutoMapper is not working for a Container class

Hello, I have an AutoMapper issue that has been driving me crazy for way too long now. A similar question was also posted on the AutoMapper user site but has not gotten much love. The summary is that I have a container class that holds a Dictionary of components. The components are a derived object of a common base class. I also have a...

Is it possible to use AutoMapper to wrap methods?

I have two classes: public class TestClass1 { public int TestInt { get; set; } public void TestMethod() { // Do something } } public class TestClass2 { public int TestInt { get; set; } public void TestMethod() { // Do something } } I want to create interface that I can use for both cl...