Monday 15 September 2014

entity framework - Can map model to viewModel, but viewModel to model won't work -


I use Automapper to map my domain model to my visual model and it works great. Atm, I am just changing prototypes and models, so at this point my visual model is almost an exact copy of my model and my idea for domains from my domain type of model class (That's why I have to keep the root class only. Domain is in synchronization with model).

Although mapping from the domain model to the visual model works well, mapping the visual model back to the domain model does not work very well, maps the values ​​directly into the visual model, but a complex type of lists No how can i fix it

This is a simple representation of my model:

  public class model {public int somevalue {get; Set; } Public Virtual Icons & lt; Complex type & gt; The list is received; Set; }} Public class viewmodel {public int some value {get; Set; } Public Virtual Icons & lt; Complex type & gt; The list is received; Set; }} Public Class Complex Type {Public Ink; Set; }}   

In this case they refer to both the model and the scene for the complex type , so they can not be different.

Did you see whether a reverse mark is used when mapping from Vertical to the Domain Model?

  public category custom profile: profile {secure override zeros} (// mapper.CreateMap & lt; Model, ViewModel & gt; (); // mapper.crtmap & lt; ViewModel, Model & gt; (); Mapper.CreatMap & lt; Models, Vyomodal & gt; (). Reversemap (); }}   

It works perfectly well and maps everything with no problems.

  [testInitialize] Public Zero Starter () {Mapper. Getting started (conf => conf.AddProfile (new custom profile ()); } [TestMethod] Public Zero AssertConfiguration () {Mapper.AssertConfigurationIsValid (); } [TestMethod] Public Zero Test () {var model = new model () {ComplexType = new archive & lt; Complex type & gt; () {New complex type () {SomeOtherValue = 1}, new complex type () {SomeOtherValue = 4}}, some value = 3}; Var ViewModel = Mapper Map & lt; ViewModel & gt; (Model); Assurance Revolve (model. Some values, see Modell some value); Assurance Requel (model complex type. Count, see model, complex type. Count); Responsibility Eraquall (model.ComplexTypes.ElementAt (0), see ModelComplex typeElimateAit (0)); Decide. Eraquall (model.ComplexTypes.ElementAt (1), see ModelComplex typeElimateAit (1)); Model = mapper Map & lt; Model & gt; (View Modell); Assurance First (see model, some values, model some value); Decide. Eraqual (see Model Codex Type.Count, ModelComplete Type.Count); Responsibility Erequal (see Model Complex Type Elementate (0), Model Complex Type Elementate (0)); Responsibility Erequal (See Model Code: Elementate (1), Model Complex Type Elementate (1)); }    

No comments:

Post a Comment