automapper

AutoMapper - map to derived objects depend on condition

泄露秘密 提交于 2019-12-11 10:58:46
问题 I want to map source class to derived (from abstract) destination classes depend on value of some property. I have the following source classes: public partial class ApplicationDriver { public virtual ICollection<ApplicationDriverEquipment> Equipments { get; set; } } public partial class ApplicationDriverEquipment { public int Id { get; set; } [StringLength(256)] public string Make { get; set; } [StringLength(256)] public string Model { get; set; } [StringLength(256)] public string Year { get

How to map property of type `Object` with different datatypes to a corresponding classtype?

梦想与她 提交于 2019-12-11 10:51:08
问题 I have two classes: public class A{ [System.Xml.Serialization.XmlElementAttribute("type1", typeof(XMLItemType1), IsNullable=true)] [System.Xml.Serialization.XmlElementAttribute("type2", typeof(XMLItemType2), IsNullable=true)] public object Item { get; set; } } public class B{ public object Item { get; set; } } Mapping is created as follows: AutoMapper.Mapper.CreateMap<A, B>() .ForMember(domainObject => domainObject.Item , metaData => metaData.MapFrom(xmlObject => xmlObject.Item )); AutoMapper

How to Mock a list transformation using AutoMapper

谁都会走 提交于 2019-12-11 10:49:23
问题 I am using AutoMapper and have a definition of mapping engine as private readonly IMappingEngine _mappingEngine; I initialize it via constructor injection and use in the code as below var product=//Get a single product var productModel = _mappingEngine.Map<ProductModel>(product); The above works perfectly. I now need to map a list of Product to list of ProductModel The following works in the controller action var entities =//Get list of products var model = entities.Select(e => _mappingEngine

Automapper/StructureMap issues with TPL version of synchronous code

試著忘記壹切 提交于 2019-12-11 10:24:44
问题 This is my synchronous working version for some workers to do some different work given a generic workload: foreach (var worker in _workers) { worker.DoWork(workload); } I am trying to exploit existing cores via the task parallel library (TPL) using this: foreach (var worker in _workers) { var worker1 = worker; await Task.Run(() => worker1.DoWork(workload)); } await Task.WhenAll(); The intention is, that each worker is executed in its own thread. Please note that this runs in a async method,

How to map objects (DTO) on client side?

て烟熏妆下的殇ゞ 提交于 2019-12-11 09:52:00
问题 Typescript ABP + .NET Core I'm using a grid to insert rows (the grid I'm using is a component of the DevExtreme framework). Anyway, similar to other grids, it raises onRowInserting events when the records are inserted, providing the inserted row as a parameter. I need to convert that "anonymous" object (the inserted data) to my client-side DTO in this event. onRowInserting(e) { let mynewrow: ItemDto = e.data; // e.data contains the inserted row } To better understand what I need to achieve,

Nested mappings with instance version of AutoMapper

☆樱花仙子☆ 提交于 2019-12-11 09:28:58
问题 I'm trying to use nested mappings with AutoMapper, using the instance version of the mapper -- but it doesn't seem to be working. Here's two models I'm using: public class User { [Key] public string Email { get; set; } public string Hash { get; set; } public string Salt { get; set; } public string Name { get; set; } public virtual ICollection<TaskTime> TaskTimes { get; set; } public virtual ICollection<Role> Roles { get; set; } public virtual ICollection<HistoricalEstimation>

Help Me Understand AutoMapper

烈酒焚心 提交于 2019-12-11 09:06:46
问题 What is the point of AutoMapper? Could someone give me a really simple example? I have watched the video on it, but it is just not clicking. Sam 回答1: Typically AutoMapper is great at mapping between data entities and business models. E.g., lets say for instance, I have a data domain type, call it PersonEntity , and it has an array of properties: FirstName , Surname , Gender etc. I don't want to expose my data domain type through to the consuming application, so I can define business domain

When mapping (automapper) need to convert a type enum to a bool

不羁岁月 提交于 2019-12-11 08:25:25
问题 I have the following model : public class Foo { [Key] public int FooID { get; set; } public string Description { get; set; } public bool IsValid{ get; set; } } I have the following view model : public class FooViewModel { public int FooId { get; set; } public string Description { get; set; } public YesNoEnumViewModel IsValid{ get; set; } } For the type YesNoEnumViewModel I used the following enum: public enum YesNoEnumViewModel { [Display(Name = "Yes", ResourceType = typeof(UserResource))]

Error on create instance of custom member resolver in AutoMapper 6

我与影子孤独终老i 提交于 2019-12-11 07:51:02
问题 I'm using AutoMapper 6 (AutoMapper.Extensions.Microsoft.DependencyInjection) for mapping data and view models in a .net core web api application.I have an age property on view model and use custom resolver for calculate age according to birth date come from data model. This is how i add AutoMapper in StartupClass: services.AddAutoMapper(config => config.AddProfile(new AutoMapperProfiles())); And this is AutoMapper profile class: public class AutoMapperProfiles : Profile { public

AutoMapper map from collection of IConfigurationSection

空扰寡人 提交于 2019-12-11 07:46:35
问题 I've browsed documentation on mapping collections and nested mapping and mapping of nested collection, but still can't cope with my case. I have the following json config file: { "startupConfig": { "noSubscription": { "calls": [ { "percentage": 30, "techPriority": 1, "timePriority": 2 }, { "percentage": 30, "techPriority": 1, "timePriority": 2 } ] } } } And here is my code reading from the file: var config = _mapper.Map<FeedConfiguration>(_configuration .GetSection("startupConfig")