automapper

Injecting AutoMapper dependencies using Ninject

天涯浪子 提交于 2019-12-20 20:00:13
问题 I am having trouble injecting AutoMapper into an ASP.NET MVC 2 application using Ninject. I used Jimmy Bogard's post on AutoMapper and StructureMap type Configuration as a guide. public class AutoMapperModule : NinjectModule { public override void Load() { Bind<ITypeMapFactory>().To<TypeMapFactory>(); Bind<Configuration>().ToSelf().InSingletonScope().WithConstructorArgument("mapper", MapperRegistry.AllMappers); Bind<IConfiguration>().To<Configuration>(); Bind<IConfigurationProvider>().To

Using AutoMapper in the Edit action method in an MVC3 application

假装没事ソ 提交于 2019-12-20 19:39:06
问题 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

Globally apply value resolver with AutoMapper

℡╲_俬逩灬. 提交于 2019-12-20 17:36:37
问题 I'm trying to have AutoMapper take care of localizing all DateTime properties on our view models for us. We use UTC everywhere in our system and store everything in UTC in the database, but we'd like to automatically convert that to a user's time zone for display. After looking at all the options, I settled on using a ValueResolver. Here's the gist of the resolver: public class LocalizedDateTimeFormatter : ValueResolver<DateTime, DateTime> { protected override DateTime ResolveCore(DateTime

Globally apply value resolver with AutoMapper

删除回忆录丶 提交于 2019-12-20 17:36:06
问题 I'm trying to have AutoMapper take care of localizing all DateTime properties on our view models for us. We use UTC everywhere in our system and store everything in UTC in the database, but we'd like to automatically convert that to a user's time zone for display. After looking at all the options, I settled on using a ValueResolver. Here's the gist of the resolver: public class LocalizedDateTimeFormatter : ValueResolver<DateTime, DateTime> { protected override DateTime ResolveCore(DateTime

When using DTOs, Automapper & Nhibernate reflecting changes in child collections of DTO in domain object being updated

为君一笑 提交于 2019-12-20 17:29:21
问题 I'm not massively familiar with this design but I am hoping to get some guidance. I have a backend service that sends out DTOs to a WPF smart client. On the WPF smart client the user will change,delete and modify items and then the changes are sent back (client --> server). As an example, currently I am working on the Customer details form and the user has the ability to add,remove and change categories belonging to a customer in a datagrid. When the DTO is sent back to the server I would

Using Automapper to map a property of a collection to an array of primitives

萝らか妹 提交于 2019-12-20 12:40:49
问题 Given the following set of classes: class Parent { string Name { get; set; } List<Child> children { get; set; } } class Child { short ChildId { get; set; } string Name { get; set; } } class ParentViewModel { string Name { get; set; } short[] ChildIds { get; set; } } When I call Mapper.Map<Parent, ParentViewModel>(vm); Is it possible to get AutoMapper to translate the list of Child.ChildId to ParentViewModel.ChildIds ? I've tried doing something like this: Mapper.CreateMap<Child, short>()

Updating user by UserManager.Update() in ASP.NET Identity 2

一曲冷凌霜 提交于 2019-12-20 11:55:17
问题 I use ASP.NET Identity 2 in an MVC 5 project and I want to update Student data by using UserManager.Update() method. However, as I inherit from ApplicationUser class, I need to map Student to ApplicationUser before calling update method. On the other hand, when using the approach that I also used for creating new Student, there is an error due to concurrency as I create a new instance rather than update. As I am bored to solve the problem using AutoMapper , I need a stable fix to solve the

How do I get AutoMapper to not cache mapped objects?

邮差的信 提交于 2019-12-20 10:24:45
问题 When AutoMapper encounters an object that's already been mapped, it seems to use that object again, instead of trying to re-map it. I believe it does this based on .Equals() . I have a tree that's being mapped. So, a node with some properties, and children. More than one of the nodes have the same value of .Equals() , because it's based off an Id property. The children of the nodes are different and I need those re-mapped, but it's using a cached map value. Is there a way to turn the cached

Where is the best place to map from view model to domain model?

荒凉一梦 提交于 2019-12-20 09:04:03
问题 Where is the best place to do mappings from view model to domain model? By mappings I mean from my EditGrantApplicationViewModel to a GrantApplication object. Lets say that I have the following action method (partial code): [HttpPost] public ActionResult Create(EditGrantApplicationViewModel editGrantApplicationViewModel) { if (!ModelState.IsValid) { return View("Create", editGrantApplicationViewModel); } return View("Index"); } Do I need to pass editGrantApplicationViewModel to a service

Entity Framework + AutoMapper ( Entity to DTO and DTO to Entity )

时光总嘲笑我的痴心妄想 提交于 2019-12-20 08:18:50
问题 I've got some problems using EF with AutoMapper. =/ for example : I've got 2 related entities ( Customers and Orders ) and they're DTO classes : class CustomerDTO { public string CustomerID {get;set;} public string CustomerName {get;set;} public IList< OrderDTO > Orders {get;set;} } class OrderDTO { public string OrderID {get;set;} public string OrderDetails {get;set;} public CustomerDTO Customers {get;set;} } //when mapping Entity to DTO the code works Customers cust = getCustomer(id);