Data Access Layer - one of the most painful topics.
Writing a good data access layer is not a trivial task. There are an incredible number of examples of implementation, but only a few are adequate.
Is it possible to consider the implementation of the template Repository - DAL?
That's what MS offers
msdn.microsoft.com/en-us/library/ff649690.aspx
And here is the local work
habrahabr.ru/post/52173The options are pretty normal.
But when I see
“The repository is the facade to access the database.”
...
I prefer the
Domain Laye r division -
Repository -
Storage Laye r (just terms)
Layer Members
Domain layer
Aggregation root
-
martinfowler.com/bliki/DDD_Aggregate.html (in simple terms - the object model object that the Repository knows about)
Query
(actually about him) - necessarily formed in terms of the Domain
Repository
His Majesty
Repository
-
martinfowler.com/eaaCatalog/repository.htmlMapper
-
martinfowler.com/eaaCatalog/mapper.html (knows how to convert the Storage entity to Aggregation root and
vice versa )
Wow
-
martinfowler.com/eaaCatalog/unitOfWork.html (without this thing, there is no
room for error, but there is one with it)
Storage layer
Storage entity
- this is not short.
And so DAL is 6 (5 if Mapper is considered part of the Repository) blocks, each of which plays an important role.
The request is just filtering options. As a request to the Repository, I really like the idea of Specification
www.codeproject.com/Articles/670115/Specification-pattern-in-Csharp There is also
habrahabr.ru/post/171559 .
Creating separate classes of filters is work so-so, but when you start to use all this
query = CarSpecifications.ByMark( mark ).
And( CarSpecifications.ByColor( color ).Not() ) ;
cars = carRepository.Get(query);
, . , , CarSpecifications.
x=>x.GroupName == groupName - :
public class UserQueryExtensions
{
public static IQueryable<User> WhereGroupNameIs(this IQueryable<User> users, strin name)
{
return users.Where(u => u.GroupName == name);
}
}
10 , .
Or Not. DI.
. , ( ,
new ExpressionSpecification(o => o.BrandName == BrandName.Samsung);)
, Repository .)
.
( Aggregation root).
, .
– . Specification ,
, Repository ISpecification<D> Predicate<S> ?
.
S S -> D () D . , , .
: , , 50 .
S, GetAll… OutOfMemory.
, « , , ».
. , . 1
1 S, S -> D, IsSatisfiedBy( D )
2 S, S -> D, IsSatisfiedBy( D )
3 S, S -> D, IsSatisfiedBy( D )
K
50000 S, S -> D, IsSatisfiedBy( D )
50 + 50 + 50 * n , =
( , , ) ( , SQL Dos ).
?
, , m ,
50 / m + 50 + 50 * n , =
.
, , .
. … , ( ).
P.S.
, , GetAll S, S -> D , IsSatisfiedBy( D ).