Using View-Models with Repository pattern

后端 未结 3 574
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-01 05:51

I\'m using Domain driven N-layered application architecture with EF code first in my recent project, I defined my Repository contracts, In Domain

3条回答
  •  攒了一身酷
    2021-02-01 06:03

    I Kindof agree with Pedro here. using a application service layer could be benificial. if your aiming for an MVVM type of implementation i would advise to create a Model class that is responsible for holding the data that is retrieved using the service layer. Mapping the data with automapper is a really good idea if your entities, DTO's and models are named consistently (so you don't have to write a lot of manual mappings).

    In my experience using your entities/poco in viewmodels to display data will result in big balls of mud. Different views have different needs en will all add a need to add more properties to an entity. Slowly making your queries more complex and slower.

    if your data is not changing that often you might want to consider introducing (sql/database) views that will transfer some of the heavy lifting to the database (where it is highly optimized). EF handles database views fairly well. Then retrieving the entity and mapping the data (from the views) to the model or DTO becomes fairly straightforward.

提交回复
热议问题