I m currently implementing some project using the NHibernate. I dont like the mappongs stored in xml files so I am using FluentNhiberante.
1. Mapping Whole Assembly.
Before discovering this feature , I created one line foreach mapping defined in the assembly. You can replace this “useless” code with the procedure to map whole assembly. FluentNH will scan the assembly and look for classes inheriting from ClassMap<>
2. not null fields
If you want to create some fields in the DB as “not null”. use the Not.Nullable() sequence.
3. Reseting Schema for Testing
I don’t know if this is a good approach but when , I am working with NH i create an instance of test database with sample data. Everytime , I am running tests i m reseting schema , filling DB with sample data and then database is erased from memory (SQLite) or the server.
Session Factory Class
In my session factory Class i have methods to reset and update Schema
4. Generic Repository
I am the fan of the repositories used to perform all the CRUD and complex query operations. In the code I have a base repository class and complex repositories deriving from the base class.
Simple Repository used for most CRUD operations.
For more complex queries , I just create a new class deriving from the base one.