automapper

AutoMapper map IdPost to Post

心已入冬 提交于 2020-01-02 18:46:26
问题 I'm trying to map int IdPost on DTO to Post object on Blog object, based on a rule. I would like to achieve this: BlogDTO.IdPost => Blog.Post Post would be loaded by NHibernate: Session.Load(IdPost) How can I achieve this with AutoMapper? 回答1: You could define AfterMap action to load entities using NHibernate in your mapping definition. I'm using something like this for simmilar purpose: mapperConfiguration.CreateMap<DealerDTO, Model.Entities.Dealer.Dealer>() .AfterMap((src, dst) => { if (src

automapper many to one mapping

試著忘記壹切 提交于 2020-01-02 16:44:11
问题 i want to map one type to other but i have multiple properties in the first type that is required to get one property of other type for example public class A { public int a{get;set;} public int b{get;set;} public int c{get;set} } public class B { public C z{get;set;} public int c{get;set} } public class C { public int a{get;set;} public int b{get;set;} public int Total{get;set} } public class D { public C Get(A a) { var c = new C(); c.a = a.a; c.b= b.a; c.c = c.a + c.b; return c } } here I

automapper many to one mapping

限于喜欢 提交于 2020-01-02 16:44:06
问题 i want to map one type to other but i have multiple properties in the first type that is required to get one property of other type for example public class A { public int a{get;set;} public int b{get;set;} public int c{get;set} } public class B { public C z{get;set;} public int c{get;set} } public class C { public int a{get;set;} public int b{get;set;} public int Total{get;set} } public class D { public C Get(A a) { var c = new C(); c.a = a.a; c.b= b.a; c.c = c.a + c.b; return c } } here I

Controlling Namespace Prefixes in WCF XML Output

耗尽温柔 提交于 2020-01-02 07:11:14
问题 The current output of my WCF service is as follows (only a portion is shown below): <s:Body> <executeSelectSP2Response xmlns="http://tempuri.org/"> <executeSelectSP2Result xmlns:a="http://schemas.datacontract.org/2004/07/WCF_Services.DataContract" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> <a:Rows> <a:RowDetail> <a:Fields> <a:FieldDetail> <a:name>STATE_CD</a:name> <a:value>1</a:value> </a:FieldDetail> <a:FieldDetail> <a:name>STATE_CD_TXT</a:name> <a:value>Alabama</a:value> </a

Using AutoMapper to unflatten a DTO

天涯浪子 提交于 2020-01-02 04:49:08
问题 I've been trying to use AutoMapper to save some time going from my DTOs to my domain objects, but I'm having trouble configuring the map so that it works, and I'm beginning to wonder if AutoMapper might be the wrong tool for the job. Consider this example of domain objects (one entity and one value): public class Person { public string Name { get; set; } public StreetAddress Address { get; set; } } public class StreetAddress { public string Address { get; set; } public string City { get; set;

Automapper and request specific resources

北慕城南 提交于 2020-01-01 19:42:11
问题 I'm considering automapper for an asp mvc intranet app I am writing. My controllers are currently created using Unity dependency injection, where each container gets dependencies unique to the request. I need to know if automapper can be made to use a request specific resource ICountryRepository to look up an object, like so.... domainObject.Country = CountryRepository.Load(viewModelObject.CountryCode); 回答1: Couple of options here. One is to do a custom resolver: .ForMember(dest => dest

Can i map multiple objects to a destination object using automapper

冷暖自知 提交于 2020-01-01 19:34:16
问题 UserAccount objUserAccount=null; AutoMapper.Mapper.CreateMap<AccountBO, UserAccount>(); objUserAccount = AutoMapper.Mapper.Map<AccountBO, UserAccount>(lstAcc[0]); Up to this point it is mapping AccountBO properties fine. Now I have to map object objAddressBO properties to destination including above mapped values. for this I have written code as below following to above lines of code. AutoMapper.Mapper.CreateMap<AddressBO,UserAccount>(); objUserAccount=AutoMapper.Mapper.Map<AddressBO

Automapper - AssertConfigurationIsValid call fails but mapping still works

醉酒当歌 提交于 2020-01-01 16:50:22
问题 Not sure if this is a bug or I'm not using it right, but seems like Automapper can map properties even though AssertConfigurationIsValid fails. In the following tests, ShouldMapSourceList will pass even though AssertConfigurationIsValid fails in ShouldValidateAgainstSourceListOnly : using AutoMapper; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace AutoMapperTests { [TestClass] public class CreateMapTests { private class A { public string PropID { get; set; } public string PropB

Automapper - AssertConfigurationIsValid call fails but mapping still works

一世执手 提交于 2020-01-01 16:50:12
问题 Not sure if this is a bug or I'm not using it right, but seems like Automapper can map properties even though AssertConfigurationIsValid fails. In the following tests, ShouldMapSourceList will pass even though AssertConfigurationIsValid fails in ShouldValidateAgainstSourceListOnly : using AutoMapper; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace AutoMapperTests { [TestClass] public class CreateMapTests { private class A { public string PropID { get; set; } public string PropB

Flatten self referencing object in Auto Mapper

六月ゝ 毕业季﹏ 提交于 2020-01-01 14:24:38
问题 I have a self referencing model that I would like to convert to a flat list. The model looks like this. public class Node { public List<Node> Nodes { get; set; } public Person Person { get; set; } public Language Language { get; set; } } public class NodeDTO { public PersonDTO Person { get; set; } public LanguageDTO Language { get; set; } } public class NodeListDTO { public List<NodeDTO> Nodes { get; set; } } I want all nodes in the hierarchy to be flattend to one single list in my DTO object