automapper

Map JSON object to C# class property array

强颜欢笑 提交于 2021-01-29 18:00:30
问题 JSON { "SoftHoldIDs": 444, "AppliedUsages": [ { "SoftHoldID": 444, "UsageYearID": 223232, "DaysApplied": 0, "PointsApplied": 1 } ], "Guests": [ 1, 2 ] } In the above JSON SoftholdIDs is integer and AppliedUsages is class array property in C# Model Issue is --How we can map JSON to class property. Class code public class ReservationDraftRequestDto { public int SoftHoldIDs { get; set; } public int[] Guests { get; set; } public AppliedUsage[] AppliedUsages { get; set; } } public class

Why doesn't automapper reverse the setting “derive all inherited”?

情到浓时终转凉″ 提交于 2021-01-29 16:16:27
问题 We are mapping domain hierarchy to the Dto hierarchy and used ReverseMap() to simplify mapping back to domain. Including all the individual derivates into the mapping was pretty annoying. That's why we've tried to use IncludeAllDerived(). That did work good for some time, but after a while we've got strange exceptions: System.ArgumentException : Cannot create an instance of abstract type Xxx.Base After some investigations we've found out, that it was due to using the IncludeAllDerived(). As

How can register profiles in Automapper from different assemblies?

…衆ロ難τιáo~ 提交于 2021-01-29 11:21:14
问题 I have an application (NET Core) with many assemblies: WebAPI (contain view models and consume DTO) Services (contain DTO and consume Domain entities) On WebAPI assembly I registered automapper profiles automatically with this line: services.AddAutoMapper(); With this line I can convert view models to DTO (and backwards) But I need register profiles located on Services layer to convert DTO to Domain entities (and backwards) Evidently, Automapper not found this profiles. What's the best way to

How to map a class to a subclass with Automapper?

耗尽温柔 提交于 2021-01-29 03:54:11
问题 If I have a class: public class MainClass { public string StringA {get; set;} public string StringB {get; set;} public string StringC {get; set;} public string Candy {get; set; } } Now I want to map that to another class public class NewClass { public string StringA {get; set;} public string StringB {get; set;} public string StringC {get; set;} public CandyObj Candy {get; set; } } and CandyObj is simply: public class CandyObj { public string CandyID {get; set;} public string CandyName {get;

How can I use automapper to map 2 enums that use different casing

我与影子孤独终老i 提交于 2021-01-28 20:33:18
问题 I have many enums that I want to keep all caps that I have to map to another system that has no standard at all (caps, no caps, pascal, camel). I can't find an automapper flag to tell it to ignore case for enums. I could use a custome converter for each enum but I would prefer a generic converter since there are so many. Some answers here have implied that automapper does this already. I don't get that from my testing. If I have these enums: public enum AllCaps { VALUE1, VALUE2, VALUE3 }

Could not load file or assembly 'Microsoft.VisualStudio.Diagnostics.PerformanceProvider, Version=14.0.0.0

。_饼干妹妹 提交于 2021-01-28 19:11:43
问题 I've got error assembly when publishing to production so far I've tried to: clean bin and obj rebuild solution manually add Microsoft.VisualStudio.Diagnostics.PerformanceProvider library set application pool to enable 32 bit aplication Intall visual studio on production server using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; using System.Text; using AutoMapper; public class AutoMapperConfig { public static MapperConfiguration

How to handle invalid dates with Automapper?

半世苍凉 提交于 2021-01-28 14:42:49
问题 So I have a source db column with a date where the type is string, not date, so as you would expect there are occasionaly invalid dates such as "10-31-". The source is beyond my control so I can't fix it there (add validation). I'm using automaper (version 9) and I've been trying to use the .MapFrom but to be honest, I'm reasonably new to Automapper and have no real clue as to what I'm doing. I've read over the documentation and it didn't help me. The destination date column is nullable, so I

How to handle invalid dates with Automapper?

删除回忆录丶 提交于 2021-01-28 14:41:36
问题 So I have a source db column with a date where the type is string, not date, so as you would expect there are occasionaly invalid dates such as "10-31-". The source is beyond my control so I can't fix it there (add validation). I'm using automaper (version 9) and I've been trying to use the .MapFrom but to be honest, I'm reasonably new to Automapper and have no real clue as to what I'm doing. I've read over the documentation and it didn't help me. The destination date column is nullable, so I

Automapper Mapping, inheritance from generic list

空扰寡人 提交于 2021-01-28 11:47:52
问题 public class Flight { public CabinCollection Cabins { get; set; } } public class CabinCollection : List<Cabin> { public Cabin Lowest { set; get; } } source and dest class have the same members 1) Mapper.Initialize(cfg => { cfg.CreateMap<Domain.Flight, Contract.Flight>(); cfg.CreateMap<Domain.Cabin, Contract.Cabin>(); }); List<Flight> res = Mapper.Map<List<Flight>>(flights); It works but the member 'lowest' is null 2) Mapper.Initialize(cfg => { cfg.CreateMap<Domain.Flight, Contract.Flight>();

Automapper Mapping, inheritance from generic list

江枫思渺然 提交于 2021-01-28 11:40:53
问题 public class Flight { public CabinCollection Cabins { get; set; } } public class CabinCollection : List<Cabin> { public Cabin Lowest { set; get; } } source and dest class have the same members 1) Mapper.Initialize(cfg => { cfg.CreateMap<Domain.Flight, Contract.Flight>(); cfg.CreateMap<Domain.Cabin, Contract.Cabin>(); }); List<Flight> res = Mapper.Map<List<Flight>>(flights); It works but the member 'lowest' is null 2) Mapper.Initialize(cfg => { cfg.CreateMap<Domain.Flight, Contract.Flight>();