automapper

How do I debug AutoMapper.AutoMapperMappingException

前提是你 提交于 2019-12-03 12:56:20
Is there some way to get some more detail from automapper when I get this exception: AutoMapper.AutoMapperMappingException Often it will tell me the 2 types of the mapping, but not which resolver or part of the mapping is failing. Simple answer, is to call this method, preferably in your unit test. // ensure your configuration mappings are loaded first (bootstrapper) Mapper.AssertConfigurationIsValid(); see: http://docs.automapper.org/en/stable/Getting-started.html#how-do-i-test-my-mappings One thing that fixed my problem was adding this line to the mapping. .ForAllMembers(op=>op.Condition(x=>

Automapper - want case sensitive

こ雲淡風輕ζ 提交于 2019-12-03 12:52:36
From similar questions on here I have read here that AutoMapper used to be case sensitive, but is now case insensitive. I want it case sensitive - can't see any way to change this, and none of the other questions Re this showed how to do it (I did look). Any ideas anyone? Thanks Imran Ali Khan You can Refer : DataReaderMapper should create case-insensitive mappings by default http://automapper.codeplex.com/workitem/6127 you can control this in Mapper.Initialize as the answer AutoMapper: Mapping between a IDataReader and DTO object another good post with examples on naming convention mappings:

Map async result with automapper

故事扮演 提交于 2019-12-03 12:36:17
问题 We are createing a Web.Api application of a angularjs application. The Web.Api returns a json result. Step one was getting the data: public List<DataItem>> GetData() { return Mapper.Map<List<DataItem>>(dataRepository.GetData()); } That worked like a charm. Then we made the data repo async and we changed to code to work with it. public List<DataItem>> GetData() { return Mapper.Map<List<DataItem>>(dataRepository.GetDataAsync().Result); } Stil no problems. Now we wanted to make my Web.Api full

Using AutoMapper in the Edit action method in an MVC3 application

…衆ロ難τιáo~ 提交于 2019-12-03 12:29:01
Here is my controller code, which works 100% as I need it to. However the POST method isn't using the AutoMapper and that is not OK. How can I use AutoMapper in this action method? I'm using Entity Framework 4 with the Repository Pattern to access data. public ActionResult Edit(int id) { Product product = _productRepository.FindProduct(id); var model = Mapper.Map<Product, ProductModel>(product); return View(model); } [HttpPost] public ActionResult Edit(ProductModel model) { if (ModelState.IsValid) { Product product = _productRepository.FindProduct(model.ProductId); product.Name = model.Name;

ITypeConverter interface has been changed in AutoMapper 2.0

本秂侑毒 提交于 2019-12-03 12:00:38
The ITypeConverter interface has been changed to have a "TDestination Convert(ResolutionContext context)" instead of "TDestination Convert(TSource source)" for the Convert method. http://automapper.codeplex.com/wikipage?title=Custom%20Type%20Converters In my code, now I get this error: 'BusinessFacade.Mappers.DecimalToNullableInt' does not implement interface member 'AutoMapper.ITypeConverter.Convert(AutoMapper.ResolutionContext)' Any good full sample for new mapper like my mappers ? I don't want change any code (or minimum code) in my projects... My mapper public class DecimalToNullableInt :

Dotnet Core中使用AutoMapper

[亡魂溺海] 提交于 2019-12-03 11:39:23
官网: http://automapper.org/ 文档: https://automapper.readthedocs.io/en/latest/index.html GitHub: https://github.com/AutoMapper/AutoMapper/blob/master/docs/index.rst 什么是AutoMapper?   AutoMapper是一个对象-对象映射器。 对象-对象映射通过将一种类型的输入对象转换为另一种类型的输出对象来工作。 使AutoMapper变得有趣的是,它提供了一些有趣的约定,以免去搞清楚如何将类型A映射为类型B。只要类型B遵循AutoMapper既定的约定,就需要几乎零配置来映射两个类型。 为什么要使用AutoMapper?   映射代码很无聊。 测试映射代码更加无聊。 AutoMapper提供了简单的类型配置以及简单的映射测试。 真正的问题可能是“为什么使用对象-对象映射?”映射可以在应用程序中的许多地方发生,但主要发生在层之间的边界中,例如UI /域层或服务/域层之间。 一层的关注点通常与另一层的关注点冲突,因此对象-对象映射导致分离的模型,其中每一层的关注点仅会影响该层中的类型。 AutoMapper的使用场景:   AutoMapper是对象到对象的映射工具。在完成映射规则之后

What's Automapper for?

安稳与你 提交于 2019-12-03 11:21:11
问题 What’s Automapper for? How will it help me with my domain and controller layers (asp.net mvc)? 回答1: Maybe an example will help here... Let's say you have a nicely-normalized database schema like this: Orders (OrderID, CustomerID, OrderDate) Customers (CustomerID, Name) OrderDetails (OrderDetID, OrderID, ProductID, Qty) Products (ProductID, ProductName, UnitPrice) And let's say you're using a nice O/R mapper that hands you back a well-organized domain model: OrderDetail +--ID +--Order |--+-

Using AutoMapper to map a string to an enum

陌路散爱 提交于 2019-12-03 10:58:33
I have the following classes domain and Dto classes: public class Profile { public string Name { get; set; } public string SchoolGrade { get; set; } } public class ProfileDTO { public string Name { get; set; } public SchoolGradeDTO SchoolGrade { get; set; } } public enum SchoolGradeDTO { [Display(Name = "Level One"] LevelOne, [Display(Name = "Level Two"] LevelTwo, } I used the following method: Mapper.CreateMap<Profile, ProfileDTO>() .ForMember(d => d.SchoolGrade , op => op.MapFrom(o => o.SchoolGrade)) Afterwards, I get the following error: Requested value 'Level Two' was not found. How do I

Automapper with base class and different configuration options for implementations

China☆狼群 提交于 2019-12-03 09:53:36
I have two classes (MVC view model) which inherits from one abstract base class. abstract class BaseModel { } class Car : BaseModel { public string Speed { get; set; } } class Camper : BaseModel { public int Beds { get; set; } } and want to configure AutoMapper with base class, something like: Mapper.CreateMap<BaseModel, DataDestination>(); var someObj = new DataDastination(); Mapper.Map(instanceOfBaseModel, someObj); Here I get error, because Automapper doesn't have configuration of Car or Camper. Tried configuring Automapper with something like this: Mapper.CreateMap<BaseModel,

AutoMapper多个源映射到一个Dto

為{幸葍}努か 提交于 2019-12-03 09:30:35
AutoMapper多个源映射到一个Dto 首先要引入AutoMapper(我电脑用的8.0,9.0版本) 1. 定义源映射对象 Model如下: 实体Social /// <summary> /// 社会属性 /// </summary> public class Social { public int Age { get; set; } public bool IsMarried { get; set; } public string Name { get; set; } } 实体Physical /// <summary> /// 身体属性 /// </summary> public class Physical { public string Eye { get; set; } public string Mouth { get; set; } } PeopleDto public class PeopleDto { public string Eye { get; set; } public string Mouth { get; set; } public string Ear { get; set; } public int Age { get; set; } public bool IsMarried { get; set; } } 2. 映射配置 public