automapper

AutoMapper: What is the difference between PreserveReferences and MaxDepth?

主宰稳场 提交于 2019-11-30 21:06:16
I'm a little bit confused. I can't find out the difference between PreserveReferences and MaxDepth . Let's suppose we have the following DTOs and models. public class PersonEntity { public PersonEntity InnerPerson { get; set; } } public class PersonModel { public PersonModel InnerPerson { get; set; } } As written in the documentation: Previously, AutoMapper could handle circular references by keeping track of what was mapped, and on every mapping, check a local hashtable of source/destination objects to see if the item was already mapped. It turns out this tracking is very expensive, and you

How to deep clone objects containing an IList property using AutoMapper

懵懂的女人 提交于 2019-11-30 17:40:02
I am trying to deep clone the following class using AutoMapper: public class MainData { public MainData() { Details = new List<Detail>(); } public int Id { get; private set; } public DateTime LastUpdate { get; private set; } public IList<Detail> Details { get; private set; } public int Prop1 { get; set; } public int Prop2 { get; set; } public void AddDetail(Detail detail) { Details.Add(detail); } public void RemoveDetail(Detail detail) { Details.Remove(detail); } public MainData Clone() { Mapper.Reset(); Mapper.CreateMap<MainData, MainData>().ForMember(d => d.Id, o => o.Ignore()); // Mapper

Getting an exception with AutoMapper

半世苍凉 提交于 2019-11-30 17:28:52
I'm unit testing a method which uses automapper to map a class from my domain to a linq to sql class. Roughly, the classes and mapping are below (The SupplierEligibilityAllocated is a L2S auto generated class). public class SupplierEligibilityTransactionByQuantity { public decimal Eligibility { get; private set; } public decimal CoreValue { get; private set; } public int? TransactionId { get; private set; } public SupplierTransactionStatus Status { get; private set; } public int? DebitId { get; set; } public int ManifestId { get; private set; } } public partial class

Is AutoMapper AssertConfigurationIsValid enough to ensure good mapping?

别说谁变了你拦得住时间么 提交于 2019-11-30 17:08:08
I'd like to ask you a question about AutoMapper. We are unit testing our mapping like that: var dtoFiltrePersonne = new DtoFiltrePersonne { Prop1 = "Test", Prop2 = 1234 }; Mapper.CreateMap<FiltrePersonne, DtoFiltrePersonne>(); var filtrePersonne = DtoAutoMappeur<DtoFiltrePersonne, FiltrePersonne>.Instance.MapFromDtoToEntity(dtoFiltrePersonne); Assert.AreEqual(dtoFiltrePersonne.Prop1, filtrePersonne.Prop1); Assert.AreEqual(dtoFiltrePersonne.Prop2, filtrePersonne.Prop2); I'd like to know if this unit test provides the same coverage? Mapper.CreateMap<FiltrePersonne, DtoFiltrePersonne>();

How to deep clone objects containing an IList property using AutoMapper

落花浮王杯 提交于 2019-11-30 16:42:54
问题 I am trying to deep clone the following class using AutoMapper: public class MainData { public MainData() { Details = new List<Detail>(); } public int Id { get; private set; } public DateTime LastUpdate { get; private set; } public IList<Detail> Details { get; private set; } public int Prop1 { get; set; } public int Prop2 { get; set; } public void AddDetail(Detail detail) { Details.Add(detail); } public void RemoveDetail(Detail detail) { Details.Remove(detail); } public MainData Clone() {

Getting an exception with AutoMapper

与世无争的帅哥 提交于 2019-11-30 16:39:54
问题 I'm unit testing a method which uses automapper to map a class from my domain to a linq to sql class. Roughly, the classes and mapping are below (The SupplierEligibilityAllocated is a L2S auto generated class). public class SupplierEligibilityTransactionByQuantity { public decimal Eligibility { get; private set; } public decimal CoreValue { get; private set; } public int? TransactionId { get; private set; } public SupplierTransactionStatus Status { get; private set; } public int? DebitId {

Is AutoMapper AssertConfigurationIsValid enough to ensure good mapping?

对着背影说爱祢 提交于 2019-11-30 16:27:27
问题 I'd like to ask you a question about AutoMapper. We are unit testing our mapping like that: var dtoFiltrePersonne = new DtoFiltrePersonne { Prop1 = "Test", Prop2 = 1234 }; Mapper.CreateMap<FiltrePersonne, DtoFiltrePersonne>(); var filtrePersonne = DtoAutoMappeur<DtoFiltrePersonne, FiltrePersonne>.Instance.MapFromDtoToEntity(dtoFiltrePersonne); Assert.AreEqual(dtoFiltrePersonne.Prop1, filtrePersonne.Prop1); Assert.AreEqual(dtoFiltrePersonne.Prop2, filtrePersonne.Prop2); I'd like to know if

How to map an int to its enum description using AutoMapper during a queryable projection?

为君一笑 提交于 2019-11-30 16:15:16
问题 Here is the enum extension method to get its description attribute. public static string GetDescription(this Enum enumeration) { if (enumeration == null) throw new ArgumentNullException(); var value = enumeration.ToString(); var type = enumeration.GetType(); var descriptionAttribute = (DescriptionAttribute[]) type.GetField(value).GetCustomAttributes(typeof (DescriptionAttribute), false); return descriptionAttribute.Length > 0 ? descriptionAttribute[0].Description : value; } Here is the source

Mapping flat JSON/Dictionary to model (containing sub classes)

谁都会走 提交于 2019-11-30 16:04:18
问题 I want to turn a flat json string into a model, the destination class has subclasses, and the flat json has all of the sub class objects with prefix; like "{classname}.{property}". { "FirstName": "Joey", "LastName": "Billy", "EmploymentDetails.JobTitle": "JobTitle", "EmploymentDetails.StartDate": "2015-01-01T00:00:00", "ContactDetails.HouseNumberName": "10", "ContactDetails.Road": "Road" } This is my destination class: public class Person { public string FirstName { get; set; } public string

How to avoid circular references with AutoMapper?

天大地大妈咪最大 提交于 2019-11-30 15:54:58
问题 I have the following models (and corresponding DTOs): public class Link { public int Id {get; set;} public int FirstLinkId {get; set;} public int SecondLinkId {get; set;} public virtual Link FirstLink {get; set;} public virtual Link SecondLInk {get; set;} } public class OtherObject { public int Id {get; set;} public int LinkId {get; set;} public string Name {get; set;} public virtual Link Link {get; set;} } In my scenario, I can have a Link object where FirstLink and/or SecondLink can be null