ASP.NET MVC: best practice or design pattern for getting DTO / EditModel into a database

I use AutoMapper to create a DTO for ViewModel and EditModel. I cannot find a good example of how to take the EditModel and apply the changes it contains to the database.

At first I looked at using AutoMapper as a two-way mechanism, but this is clearly not recommended: http://www.lostechies.com/blogs/jimmy_bogard/archive/2009/09/17/the-case-for-two-way-mapping-in -automapper.aspx

So, what is the best way (design pattern) to get a DTO or EditModel from a controller in a data warehouse?

UPDATE: based on some answers, I should mention that I am using the repository design pattern and Entity Framework.

UPDATE: My question is too subjective as there is no general practice for this. My conclusion is that many people use AutoMapper in both directions, even if others do not recommend it.

+3
source share
4 answers

In this simplest form, you just need to use AutoMapper to map your model to a Domain / DTO object, and then save it in your data store, but you do.

So, something that is pretty much related to one of the projects that I did:

Mapper.Map(modelObject, domainObject);
domainObject.Save();
return domainObject.Id;

You might want to return id from any method you call so that you can use it further. This is just an example, but what are the basics of it ...

EDIT: , : Mapper.Map ViewModel Domain. Save() , . IRepository.Save(). nHibernate SaveOrUpdate

AutoMapper - :

Mapper.CreateMap<OrderDomain, OrderViewDTO>();

Mapper.CreateMap<OrderSaveDTO, OrderDomain>();

?

+1

, , . , , , , ORM Relation Mapper. - NHibernate Entity Framework. .

AutoMapper - , , , (, ).

: , , - ASP.NET MVC, .

0

AutoMapper . , . AutoMapper , , , .

0

NHibernate - DTO . Entity Framework -, ASP.NET MVC. - NHibernate - .

-2

Source: https://habr.com/ru/post/1774425/


All Articles