in·dom·i·ta·ble
adj.
Incapable of being overcome, subdued, or vanquished; unconquerable.
29th
JAN
Schema Generation using FluentNHibernate and S#arp Architecture
Posted by indomitablehef | Filed under S#arp Architecture, NHibernate
This took me several hours to figure out, and even though it makes me look bad to admit that, I figured I’d share what I eventually came up with.
I’ve been using S#arp Architecture for ASP.Net MVC, which uses FluentNHibernate. The S#arp Architecture project template generates the following test, used to test the FluentNHibernate mappings:
1 2 3 4 5 6 7 8 9 10 11 12 | [TestFixture] [Category("DB Tests")] public class MappingIntegrationTests { [SetUp] public virtual void SetUp() { string[] mappingAssemblies = RepositoryTestsHelper.GetMappingAssemblies(); NHibernateSession.Init(new SimpleSessionStorage(), mappingAssemblies, "../../../../app/FuBar1.Web/Hibernate.cfg.xml"); } <...> |
To do the Schema Export based on the FluentNHibernate mappings, you need to get at the NHibernate Configuration object.
Luckily, the NHibernateSession.Init method returns the Configuration object. So, I modified the Setup for the MappingIntegrationTests class to:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | [TestFixture] [Category("DB Tests")] public class MappingIntegrationTests { private Configuration cfg; [SetUp] public virtual void SetUp() { string[] mappingAssemblies = RepositoryTestsHelper.GetMappingAssemblies(); cfg = NHibernateSession.Init(new SimpleSessionStorage(), mappingAssemblies, "../../../../app/FuBar1.Web/Hibernate.cfg.xml"); } <...> |
…capturing the Configuration in a private variable.
I then added this [Test] method to the class, to do the SchemaExport:
1 2 3 4 5 6 7 | [Test] public void SchemaGeneration() { var session = NHibernateSession.SessionFactory.OpenSession(); new SchemaExport(cfg).Execute(true, false, false, false, session.Connection, null); Assert.IsTrue(true); } |
and viola! I get this in the test output window (ReSharper, NUnit)

Yeah, that’s right. Monkeys.
8th
DEC
Fluent NHibernate
Posted by indomitablehef | Filed under NHibernate, ORM
I started playing around with Fluent NHibernate today. What a fantastic improvement over the old .hbm (xml) file configuration! Details here.
Recent Posts
Recent Comments
- Open Floor Plan vs. Private Offices « Step Into Design on It's Caves AND Commons...
- indomitablehef on Forms Authentication in Asp.Net MVC, Part II
- Dugald Wilson on Forms Authentication in Asp.Net MVC, Part II
- MyWeeklyLinks – Week 5 « Ole Morten Amundsen on Implementing Done, In Process, and Ready Queues in LeanKit Kanban
- indomitablehef on Schema Generation using FluentNHibernate and S#arp Architecture
Categories
- .Net (5)
- Agile (17)
- Alt.Net (3)
- Anti Patterns (3)
- Asp.Net MVC (9)
- Continuous Integration (4)
- Craftsmanship (1)
- CruiseControl.Net (1)
- DDD (6)
- DevLink (2)
- jQuery (2)
- Kanban (4)
- Lean (2)
- LeanKit (3)
- NAnt (2)
- NHibernate (2)
- ORM (1)
- Personal (4)
- Productivity (6)
- qUnit (2)
- Refactoring (1)
- S#arp Architecture (2)
- SOLID (1)
- SqlTdd (5)
- TDD (17)
- Tools (12)
- Uncategorized (11)
- Visual Studio (4)


