automapper

Automapper with Entity Framework, Initialization Error

回眸只為那壹抹淺笑 提交于 2019-12-25 07:18:44
问题 I have an EF6 MVC app using Code First to generate the models. I am trying to create a mapping using AutoMapper between the model and a view model representation of that model. However, when I do the mapping I receive the error: Mapper not initialized. Call Initialize with appropriate configuration. If you are trying to use mapper instances through a container or otherwise, make sure you do not have any calls to the static Mapper.Map methods, and if you're using ProjectTo or UseAsDataSource

Automapper fails to map two entities

梦想的初衷 提交于 2019-12-25 03:04:09
问题 I'm trying to map two entities - ProductPictureDTO with ProductPictureBDO - using the Automapper, but I get an exception and I'm not able to understand what is thew mistake. The error Missing type map configuration or unsupported mapping. Mapping types: ProductPictureDTO -> Guid ERP.DTO.Products.ProductPictureDTO -> System.Guid Destination path: ProductPictureBDO Source value: ERP.DTO.Products.ProductPictureDTO Here below you can see ProductPictureDTO [DataContract] public class

Generics & static classes. Implement query helper method

折月煮酒 提交于 2019-12-25 02:59:35
问题 Currently we implement a mapping service like this (the service uses automapper, and we make use of the projection feature on it for this part) // Injected // IGenericRepository<Entity> entityRepo var query = this.entityRepo .FindAll(a => a.Id == someId) .Take(1); var result = this.mappingService .Map<Entity, EntityDto>(query) .FirstOrDefault(); I'd like to create an extension that would allow me to do the following var result = this.entityRepo .FindAll(a => a.Id == someId) .Take(1).Map

Is there a way in AutoMapper to specify that all strings being mapped are to be trimmed

冷暖自知 提交于 2019-12-25 02:57:36
问题 I'm converting a WinForms app to ASP.NET MVC4 and trying to implement a ViewModel approach using AutoMapper to map between the domain entities and the ViewModels, mostly to flatten the more complex object graphs into ViewModels for easy binding in the views. The problem I'm running into is that when leaving some fields blank that the domain model wants to apply a Trim() a NullReferenceException is thrown. Originally this was all handled in the domain objects for example in the Customer object

Handle Automapper exception?

ⅰ亾dé卋堺 提交于 2019-12-25 02:46:26
问题 Using mvc5 with automapper I have following: In Controller : [HttpPost] public ActionResult LunchMenu_Create_Index(VmSysMenuCreate menu) { try { var domainMenu = Mapper.Map<VmSysMenuCreate, Menu>(menu); } catch (Exception ex) { return Content("Error msg"); } return Content("Succes"); } Mapping: Mapper.CreateMap<VmSysMenuCreate, Menu>() .ForMember(c => c.Id, op => op.MapFrom(v => v.Id)) .ForMember(c => c.MenuDate, op => op.ResolveUsing(data => { try { DateTime convertedDate = Convert

How to use Url.Content(“~/asdf”) inside automapper projection

﹥>﹥吖頭↗ 提交于 2019-12-25 02:23:26
问题 I am trying to use the UrlHelper's Content method inside an automapper projection, but it fails after the first request. My map creation code looks like the following: protected override void Initialize(RequestContext requestContext) { base.Initialize(requestContext); Mapper.CreateMap<MyObject, MyMappedObject>() .ForMember(dest => dest.Url, opt => opt.MapFrom(src => Url.Content("~/something/") + src.Id)); } The first request works fine, but subsequent requests throw a NullReferenceException

Automapper - Error mapping types. Mapping types: IEnumerable`1 -> IEnumerable`1 System.Collections.Generic.IEnumerable`1[[TicketTO, app.DTO

自古美人都是妖i 提交于 2019-12-25 01:55:24
问题 I have an ASP.Net Core C# application & using AutoMapper DTO public class MovieTO { public int Id { get; set;} public IEnumerable<TicketTO> Tickets { get; set;} } public class TicketTO { public string Prop1{ get; set;} public string Prop2{ get; set;} public string Prop3{ get; set;} public string Prop4{ get; set;} } Domain Entity public class Movie { public int Id { get; set;} public IEnumerable<BasicTicket> Tickets { get; set;} } public class BasicTicket { } public class RegularTicket :

How to do mapping using AutoMapper from DTO to Model both PUT/POST?

只谈情不闲聊 提交于 2019-12-25 01:23:36
问题 I've managed to do the AutoMapper as follow from Model to DTOs and this works well. private ApplicationDbContext db = new ApplicationDbContext(); private MapperConfiguration configuration = new MapperConfiguration(cfg => cfg.CreateMap<Activity, ActivityDTO>() .ForMember(dto => dto.OwnerName, conf => conf.MapFrom(ol => ol.User.FirstName + " " + ol.User.LastName)) .ForMember(dto => dto.CategoryName, conf => conf.MapFrom(ol => ol.Category.Name))); // GET: api/v1/Activities/5 [HttpGet]

Automapper mapping a list of ids to objects in many-to-many scenario

流过昼夜 提交于 2019-12-24 23:14:56
问题 I'm looking for the best way to handle this with Automapper My simplified domain model (all IDs are auto generated by the DB): public class Product { public long Id { get; set; } public List<OrderProduct> OrderProducts { get; set; } } public class Order { public long Id { get; set; } public List<OrderProduct> OrderProducts { get; set; } } public class OrderProduct { public long Id { get; set; } public long ProductId { get; set; } public long OrderId { get; set; } public Product Product { get;

IEnumerable to EntityCollection failed mapping with automapper using nested mapping

南楼画角 提交于 2019-12-24 20:13:59
问题 Starting with 2.2.0 I'm having a problem with nasted mapping. I have two models which I need to map: an EntityObject model (autogenerated by EF from DB) and a simple Data Model. EntityObject model contains an EntityCollection property of another EntityObject model type, Data Model contains an IEnumerable of another Data Model type: these fields should also be mapped. As an example: public class AnotherDataModel { //Some properties } public class DataModel { //Some properties private