c# - How do I map a model with nested properties to a flat Dto? -
I am trying to make mapping from my unit model to a DTO, but every time I am trying to create it I am Mapping
I have two domain classes. It is a simplification of our model (for example, Then I want to map Is there a way to make this mapping in mapping without specifying all areas of the This is effectively represented by automaker profiles: To do this, the I understand that I can do this by specifying each property in the "Whether to create this mapping without explicitly specifying all the fields of the device Is there a way in which domain model in mapping? " Yes, you can use naming conventions in your DTO object and it will allow you to enter them in the map form. As an example: Your values are in the key and in the Example: devices are many properties that represent a group of different things) :
class device {public entity name}; Set;}} Class DeviceAccessToken {public device device {get; Set;} public string key {get; Set;} public string secret {get; Set}}}
DeviceAccessToken to this
DeviceDto (also simple, most of the fields in it) Exists in the original
device model):
device domain model?
Category DeviceMappingProfile: Profile {Secure Override Zero Configure () {this.CreateMap & lt; DeviceAccessToken, DeviceDto & gt; (); this. Createmap & lt; Device, DeviceDto & gt; (). For mail (dest => dest.Key, opt = & gt; opt.Ignore ()) for mail (dest = & gt; dest.Secret, opt => opt.Ignore ( )); }}
.AllMembers call was an unsuccessful attempt, it should not work as I saw.
device
DeviceAccessToken and
DeviceDto , to map them Will not be required. As the
device is a nested object, your DTO can use the
DeviceName conference.
Using the
system; Using Automapers; Class device {public string name {get} Set;}} Class DeviceAccessToken {public device device {get; Set;} public string key {get; Set;} public string secret {get; Set;}} Class DeviceDto {public string DeviceName {get; Set;} public string key {get; Set;} public string secret {get; Set;}} Public Class Program {Public Zero Main ()} {// Automapper Mapper Configure Caterpap & lt; DeviceAccessToken, DeviceDto & gt; (); Var dat = new DeviceAccessToken {device = new device} {name = "dev name"}, key = "key", secret = "secret"}; Var dto = Mapper Map & lt; DeviceDto & gt; (DAT); Console.WriteLine (dto.DeviceName); Console.WriteLine (dto.Key); Console.WriteLine (dto.Secret); }}
Comments
Post a Comment