Im new to NHibernate, the configuration aspect of it has always seemed overly onerous to me. Yesterday, I came across the Auto Mapping features of Fluent NHibernate and was suitably impressed.
To educate myself, I set myself the challenge of attempting the 'Getting Started First Project' (http://wiki.fluentnhibernate.org/show/GettingStartedFirstProject) using AutoMappings and Conventions. I have to admit to not having much luck.
To summise my steps:
I made some minor changes to the database schema in the example, mainly to remove the underscores from the foreign keys (i.e. Product_id to ProductId) as this would bring it more inline with our database naming standards.
Q1) I tried to write a IHasManyConvention implementation using the ForeignKeyConvention as an example but the WithKeyColumn method doesnt seem to exist (I presume this is because I downloaded yesterdays build so subsequently the design has changed since the article was written). How do I rectify this?
I also made some minor changes to the Entities layer in the example as I thought this would make it easier, they were to rename StoresStockedIn to Stores (Product.cs) and Staff to Employees (Store.cs).
My code looks like this:
var cfg = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2005
.ConnectionString(c => c
.Is(connectionString)))
.Mappings(m => m.AutoMappings.Add(
AutoPersistenceModel.MapEntitiesFromAssemblyOf<Store>()
.Where(t => t
.Namespace == "FluentNHibernateTesting.Entities")
.ConventionDiscovery.Setup(c => c.Add<ForeignKeyConvention>())
))
.BuildSessionFactory();
I then try and add the stores, products and employees to the database as per the getting started example. The exception I get happens on the Commit and is:
object references an unsaved transient instance - save the transient instance before flushing. Type: FluentNHibernateTesting.Entities.Employee, Entity: FluentNHibernateTesting.Entities.Employee
Q2) How do I resolve this problem? I understand (from my limited reading) that it has something to do with setting up the cascade elements of object relationships correctly but Im a bit stumped about how to go about this effectively using Auto Mapping.
Q3) Is there a target release date for the Fluent project? I (like I assume many others) feel this is an excellent initiative but am mindful of using it unless it is in a stable state.
Q4) Its mentioned in many of the blogs that they are working steadily towards parity of the features in Fluent with hbn.xml. Is there a list of these missing features somewhere in order to aid with the evaluation and usage of this tool?
Appreciate the help in advance.