It’s true, I swear. It’s very simple to test if you can (C)reate, (R)ead, (U)pdate and (D)elete objects using NHibernate, and Fluent NHibernate makes it one (fluent) line of code!

Suppose we have an Employee object and we want to check that we can CRUD it AND reference to the Company (object) they work for in the mapping. It might look like this:

   1:  new PersistenceSpecification<Employee>(Session)
   2:      .CheckProperty(x => x.FirstName, "Dave")
   3:      .CheckProperty(x => x.LastName, "Jones")
   4:      .CheckProperty(x => x.MiddleInitial, "L")
   5:      .CheckProperty(x => x.DateOfBirth, new DateTime(2008, 11, 1))
   6:      .CheckProperty(x => x.Sex, _sex)
   7:      .CheckReference(x => x.Company, new Company{ CompanyID = 999, Name = "Wonder Wheels" })
   8:      .VerifyTheMappings(); 

Okay, it may not LOOK like one line of code, but I swear it is. One, long, fluent line of code.

Super sweet. If you’ve found better ways, post a comment, I LOVE to learn better ways.

 

~L

posted on Thursday, May 07, 2009 7:41 PM |

Comments

No comments posted yet.
Post Comment
Title *
Name *
Email
Url
Comment *