Tuesday, May 13, 2008

Achieving Persistence Ignorance with NHibernate

with James Kovacs

Definitions

  • POCO- plain old CLR objects
  • Domain Driven Design - For most software projects, the primary focus should be on the domain and domain logic

Tools

  • RhinoETL - alternative to SSIS

Why NHIbernate

  • uses POCOs
    • NH does not impose requirement on objects
  • no persistence code strewn throughout the framework
    • like the Entity framework
  • Promotes Domain Driven Design
  • Its all about separation of concerns, single responsibility, loose coupling, testability, re-use of code. All that fun stuff.
  • Allows you to concentrate on the business logic
    • business logic is what’s important, not how it's stored

Nhibernate

  • An ISession is a conversation with a database
    • This is not thread safe. Go higher for thread safety.
  • There are three query methods
    • HQL like LINQ but string oriented
    • Criteria is OO with added parameters
    • LINQ to NH is in the works

Remember

  • You still need to test against the database
  • Isolation helps, not only with changing the data store, but with also different versions of the data store
  • In 2.0 transactions are now required even for reads.
    • You can roll back an entire transaction if an error is encountered.
  • You can use lazy loading to speed up performance
    • Use FuturyQueryOf if you are dealing with nested for each loops.
  • You need to explicitly set your cascade rules

EFPRS

  • Our database is not normalized. We have all the expired fields that will be null for most of the time in our tables. If we normalize that, we can take advantage of NHibernates polymorphism so distinguish active and expired entries.

The Speaker

  • reminds me of a Monty Python character

Notes

  • You can code backwards with ReSharper and Ctrl+r+v

No comments: