linq2db as DTO layer
See original GitHub issueHello. We’ve been using Linq2db in a project for a while and we got to a stage where we understood that working directly with generated classes is not enough. Is it worth creating a BO and DTO separately, using linq2db?
If i would like to introduce a field UserCreated in my Users table, which would automatically use Insert date, how could i achieve that using Linq2db without an extra layer, where i would manually write my Insert function?
If then i introduce an extra layer, then in order to use linq for my queries (lets say i have
var admins = db.Users.Where(usr => usr.IsAdmin).ToList();
I would have to reproduce the exact same query on my BO class, something like this
var admins = Users.All().Where(usr => usr.IsAdmin);
which makes me load the whole list, thus generate two separated queries, which is not nice.
What is the best approach to this structure?
Thank you!
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
We need Expression Tree but not just object to object remapping, You have to write mapper only in the following way:
Or you can return Expresssion Tree for remapping:
And use in query
Ineresting that i’m thinking about universal implementation for such needs. And i have proposed interfaces for implementing this https://github.com/linq2db/linq2db/issues/230#issuecomment-412290451 Thinking about implementation of some independed
DTOEntityServices
with registration of IEntityMapping. Almost everything can be done without changing linq2db code.