Business objects built up directly from a database query
...What is it called?
More elaborate: For my application I created a nice business model to work with as in-memory objects. It's storage and view agnostic. Now, for the storage layer, there's a database: I'll construct SQL queries (the fewer the better) that selects/joins etc. all data I need from the relevant tables. A kind of "middle layer" takes the query(s) result and constructs business ob开发者_如何学Cjects with all relations.
Questions: What do you call this approach? What are the best practices?
This takes place in a .NET C# project but that's not relevant to this design question.
(I found question 441532 to be very similar but I'm interested in more design input)
Note: I do not take the ORM approach that relies on tools that do this automatically because the application requires only selected data from a relatively large database.
I think it's called ORM, or object-relational mapping.
NHibernate is one example of just such a thing.
It's generally called DDD - Domain Driven Design.
https://stackoverflow.com/questions/tagged/ddd
https://stackoverflow.com/questions/tagged/domain-driven-design
There are different ORM tools. Linq to SQL do a 1:1, which is not what you want.
What you're talking about overlaps with Domain Driven Design, where your design is driven by the domain, not the Database.
In this case, if you are using a relational Database you still need an ORM, and ORMs like Entity Framework and NHibernate allow you to flexibly "map" your entities to your database in any way you want, in a way that, if your Database needs to change for whatever reason, or you Entities have to change, for whatever reason, all you need to change is the middle "mapping" layer.
take a look at fluent nhibernate
精彩评论