dimanche 12 novembre 2017

asp.net layers design pattern

There are many questions about implementing repository pattern. Assume a table with large data and many columns with nvarcharmax columns:

Which way is better?

1-

Repository Layer : GetUsersByFilter() -> returns IEnumerable< UserDomain >

Because we are fetching all of the columns it doesn’t seem to be efficient. We are returning domain IEnumerable with all of the fields and constraints implemented on domain object and its fields.

2-

Repository Layer : GetUsersByFilter1() -> returns IEnumerable< UserDomain >

Repository Layer : GetUsersByFilter2() -> returns IEnumerable< UserDomain >

Repository Layer : GetUsersByFilter3() -> returns IEnumerable< UserDomain >

Repository Layer : GetUsersByFilter4() -> returns IEnumerable< UserDomain >

Which doesn’t return all of the UserDomain columns in each method. We can select fields which we need in select query

GetUsersByFilter1(FilterModel filterModel){

return _context
    .Users
    .Where( //filter goes here )
    .Select(x => new UserDomain {

        //just set 4 of 20 columns

}).AsEnumerable();

3-

Repository Layer : GetUsersByFilter() -> returns IQueryable< UserDomain >

Service Layer: Implement multiple methods according presentation layer needs with different select queries and filters.

Aucun commentaire:

Enregistrer un commentaire