Вопрос

I have Data Access Layer objects which represent data retrieved from a webservice.

In other hand, I have MVC Model objects which represent the same data structure but enforced with Data Annotation attributes in order to perform UI validation, etc.

Apparently, I have to swap data between DAL and Model objects for every read/write operation.

The question is whether I can simplify this approach to have just one set of objects and use them for both layers (Data Access and Model). What is the best practice?

I know there are some NuGets to sync data between those two kinds of objects. Could you please suggest which one to use? Thank you.

Это было полезно?

Решение

The best practice is to have a separate set of domain objects and mvc models. That way you can wire up all of your annotations on your viewmodel and people won't be able to post fields that you don't want the user to edit

You can also use AutoMapper to simplify binding between the two

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top