automapper

How should I implement an MVC Bootstrapper for Unity and AutoMapper?

Deadly 提交于 2019-12-12 08:46:46
问题 What is the best way to create a bootstrapper for my MVC 2 app? I'm using Unity and AutoMapper and want to abstract the loading and configuration of them as much as possible. A decent example is here (http://weblogs.asp.net/rashid/archive/2009/02/17/use-bootstrapper-in-your-asp-net-mvc-application-and-reduce-code-smell.aspx ), but UnityContainer implements IDisposable and in that example it is never cleaned up. This (Configuring Automapper in Bootstrapper violates Open-Closed Principle?) is

AutoMapper cannot convert enum to nullable int?

时间秒杀一切 提交于 2019-12-12 08:37:07
问题 I got AutoMapperMappingException exception Exception of type 'AutoMapper.AutoMapperMappingException' was thrown. ---> System.InvalidCastException: Invalid cast from 'DummyTypes' to 'System.Nullable`1[[System.Int32, ... when public enum DummyTypes : int { Foo = 1, Bar = 2 } public class DummySource { public DummyTypes Dummy { get; set; } } public class DummyDestination { public int? Dummy { get; set; } } [TestMethod] public void MapDummy() { Mapper.CreateMap<DummySource, DummyDestination>();

Using AutoMapper with F#

…衆ロ難τιáo~ 提交于 2019-12-12 07:48:53
问题 I'm trying to use AutoMapper from F#, but I'm having trouble setting it up due to AutoMapper's heavy use of LINQ Expressions. Specifically, the AutoMapper type IMappingExpression<'source, 'dest> has a method with this signature: ForMember(destMember: Expression<Func<'dest, obj>>, memberOpts: Action<IMemberConfigurationExpression<'source>>) This is typically used in C# like this: Mapper.CreateMap<Post, PostsViewModel.PostSummary>() .ForMember(x => x.Slug, o => o.MapFrom(m => SlugConverter

Entity Framework, AutoMapper, handling entity updates

南笙酒味 提交于 2019-12-12 07:38:31
问题 I just started using the Entity Framework 1.0 recently and believe I am beginning to feel the pains everyone is talking about. I'm trying to use best practices so I have a set of DTO that get mapped to and from my Entities via AutoMapper. The real catch is when I'm trying to update an object. The first gotcha was that I could not find a way to create a new entity, transfer the data from my DTO, and still have the entity ObjectContext realize that it has been changed. I used the following code

Automapper custom object

醉酒当歌 提交于 2019-12-12 06:38:54
问题 How I have configure automapper to map this: class Source { Guid Id; double Price; } To this: class Destination { Guid Id; DestinationDifference Difference; } class DestinationDifference { decimal Amount; } 回答1: First: You should really read the FAQs on how to post a question and what information should be added. (No, I'm not the downvoter) Here is an example how to get your mapping to work. Please note, that I've changed your classes a bit, because AutoMapper needs properties. Source source

AutoMapper: How to Initialize BindingFlags?

笑着哭i 提交于 2019-12-12 06:14:04
问题 When I asked this question about AutoMapper and protected properties, I received a response from Jimmy Bogard (AutoMapper co-creator). He suggested that we can initialize the BindingFlags using the code that I pasted below. The problem is, I get the following error and don't know how to fix it: "AutoMapper.IConfiguration does not contain a definition for 'BindingFlags' and no extension method..." Here's the code: Mapper.Initialize(cfg => { cfg.BindingFlags = BindingFlags.Public | BindingFlags

Use no global Mapper variable of Automapper in AfterMap

假装没事ソ 提交于 2019-12-12 06:06:23
问题 Is there a way to get the current mapping context in AutoMapper when using AfterMap? public class DefaultMappingProfile : Profile { protected override void Configure() { this.CreateMap<SomeList, List<SpecialItem>>() .AfterMap((src, dst) => dst.AddRange( src.elem.Select(Mapper.Map<SpecialItem>))); I tried to use .ConstructUsing(context => {}) but this gave me not the same results as when using AfterMap (!?). But I don't want to access the global variable Mapper here. Is there a way to get

Automapper CreateMissingTypeMaps property Warning

情到浓时终转凉″ 提交于 2019-12-12 04:30:31
问题 I think this is a repeated Question but i am unable to resolve it. here is my mapping. UserProfileVM model = AutoMapper.Mapper.DynamicMap<UserProfileVM>(objUser); But here AutoMapper gives warning. I tried to add MapperConfiguration , but i have no idea how to use it in DynamicMap<>() . var config = new MapperConfiguration(cfg => { cfg.CreateMissingTypeMaps = true; }); Now how to use my config variable for dynamic map? Or is there any global setting for these issue because i used mapper for

Reasons Using AutoMapper

荒凉一梦 提交于 2019-12-12 03:43:00
问题 I want to start using AutoMapper at our firm. The problem the my team members just don’t see any benefit with it. The main claim why we need addition abstraction when we can write our-self extensions method that doing the same. So what are the reasons I can raise against ? 回答1: My two biggest arguments for Automapper: Why write something custom when you can rely on a well-tested, convention-based library to do for you? Yes, you can write extension methods to move data between properties. But,

How to map single object properties to array of object in complex type using automapper

与世无争的帅哥 提交于 2019-12-12 03:33:13
问题 I got class structure like follows, and I've created mapping structure, but it is not working as expected. public class ResponseHeader { public ResHeader ResHeader { get; set; } } public class ResHeader { public ServiceResStatus ServiceResStatus { get; set; } public Error[] Errors { get; set; } } public class Error { public string ErrorCode { get; set; } public string ErrorDesc { get; set; } public string Source { get; set; } } public class ServiceResStatus { public string ServiceResCode {