I am trying to map CustomerDTO with AutoMapper to my domain unit ICustomer
I am using the interfaces for my domain model because the structure is injected in solid type from my LinkToSQL Database Infrastructure Layer.
Public Interface IBaseEntity & lt; TPk & gt; {TPK ID {Received; }} Public Interface ICustomer: IBaseEntity & lt; Int & gt; {String Email {Receive; Set; }} [DataContract] Public class customer DTO {[Database] Public Int ID {Received; Set; } [Database] Public String Email {get; Set; }}
Automapper mapping now
Mapper Crescent & lt; Customer DTO, IC Customer & gt; (); Mapper Createmap & lt; ICustomer, CustomerDTO & gt; (); Mapper.AssertConfigurationIsValid ();
Now where I am using mapping
Public CreateCustomerServiceResult CreateCustomer (CustomerDTO Customer) {var Result = New CreateCustomerServiceResult (); {Var originalMapped = Mapper.DynamicMap & lt; CustomerDTO, ICustomer & gt; (Customer); Var newCustomer = _customerService.CreateCustomer (original map); Var newmap = mapper Dynamic map & lt; ICustomer, CustomerDTO & gt; (New customer); result. Customer = newmap; } Hold (Exception Pre) {} Return Results; }
I have found a Dictionnary missing key exception on the "id" property ...
Got it!
The problem was due to the missing setter of IbSENTT's "ID" property.
Then everything changes works.
Public Interface IBaseEntity & lt; TPk & gt; {TPK ID {Received; Set; }}
No comments:
Post a Comment