with Benjamin Day
What is the problem?
- There is a mismatch between objects and relational databases.
- These must be unified.
Definitions
- Primitive Obsession
- Breaking things down into their smallest parts
- Is the phone number validation really the responsibility of the Person object?
- break phone number out as an object that knows if it is valid
How can we do this?
- We could have one table per class perhaps?
- Pros
- This is simple and nice
- We can even use typed DataSets
- Cons
- We have tight coupling.
- Inheritance is difficult.
- Where do we do validation?
- Object DataRow hybrid
- Has properties to control access to the columns
- However there is a lot of stuff you need to start thinking about when you go to save these
- This becomes more complicated
- For example, how do you save multiple objects in one table
- Or how do we handle nested relationships
- Unfortunately too often we are not going to do the right thing because it is hard.
Object only model
No more DataRow
We have a clean domain model pattern
Remember, objects should map to nouns that nontechnical people talk about
They have all that lovely Computer Science stuff
Unfortunately your data access layer has to adapt data to the database hurrah!
This is a lot of code.
The adapter portion is 30-50 percent of your code
This is like the saying, you can drive with you feet, but that doesn't make it a good idea
We write this and rewrite this over and over and over again
These distract us from solving the real business problems
Remember, in the end, it's all about money.
LINQ to SQL
It is available in VS.Net 2008
LINQ provides a "better typed dataset"
Unfortunately it is SQL server only :(
LINQ generates a lot of code to help you out. It does a lot of thwe work for you.
Surprisingly, the code is actually really good
Good for
However, it is closely tied to the database
It’s like a codeless CRUD
Can do polymorphism
However, is uses discriminator field.
Results in lots of null fields.
Entity Framework
Microsoft’s first ORM –
- It’s in beta
- To come out with VS2008 sp1
Can support non SQL Server databases
Has table-per-type support
This is the first release, be cautious
NHibernate
Uses XML for mapping
Is now supported by JBboss
Has no gui
It doesn't support LINQ.. yet
- has hql though
Supports polymorphic queries
It does table per type
components let you push fields out into helper objects
does concurrency
- Based on a datetime or number
You can do inheritance (joined subclass)
EFPRS
- We need to look at how concurrency is handled in our code
- Our database is not normalized because of our ExpiryDate field
- We need to set up table per type structure
- Have an agreement table, active agreement table, and an Expired Agreement table.
- Take advantage of polymorphic queries for expired types
Notes
- Are Stored Procedures really a best practice?
- Performance gain from Stored Procedures are almost gone as of slqs7
- What are you saving with a Database layer of abstraction?
- Use Stored Procedures for crud if you have really strict security requirement
- Sample applications at the web site
- ORM and architecture design and VSTS
- Go to use user groups regularly
No comments:
Post a Comment