Good evening people,
I have been using Fluent Nhibernate for a while, I've never really dug too deep into its functionality or the many ways it can be configured. In every project I have used it in I have configure it as follows:
if (nhConfig == null)
{
nhConfig = new NHibernate.Cfg.Configuration();
nhConfig.Properties.Add(NHibernate.Cfg.Environment.ProxyFactoryFactoryClass, typeof(NHibernate.ByteCode.LinFu.ProxyFactoryFactory).AssemblyQualifiedName);
// This obviously changes depending on what im trying to connect to
nhConfig.Properties.Add(NHibernate.Cfg.Environment.ConnectionDriver, typeof(NHibernate.Driver.SqlServerCeDriver).AssemblyQualifiedName);
// Configuration is simply an implementation
// of an IConfiguration interface
nhConfig.Properties.Add(NHibernate.Cfg.Environment.ConnectionString, configuration.ConnectionString);
// In this instance, this resolves to
// "NHibernate.Dialect.MsSqlCeDialect"
nhConfig.Properties.Add(NHibernate.Cfg.Environment.Dialect, configuration.Dialect.AssemblyQualifiedName);
nhConfig.Properties.Add(NHibernate.Cfg.Environment.ShowSql, "true");
_sessionFactory = Fluently.Configure(nhConfig)
.Mappings(m => m.FluentMappings.AddFromAssembly(configuration.MappingAssembly))
.ExposeConfiguration(x => new SchemaUpdate(x).Execute(false, true))
.BuildSessionFactory();
}
Apologies for the poorly formatted code block...I can never figure out how to edit the code once you paste it in without de-activating the code tags.
So as I say, in all of my other projects, this configuration code has worked fine. The database has always been a SQLExpress database (2005 || 2008) and should the table not exist in the database for the specified entity, then it is automatically created.
However, this time an SQL Compact database is required. I have created this database simply by adding a new Database item to my assembly (TestingDB.sdf) and have actually created a "Customer" table.
Now I have the following unit test:
[Test]
public void Function_CanCreateDomainObject()
{
// Create a fake entity that is mapped
Customer fakeCustomer = new Customer();
fakeCustomer.Name = "Function_CanCreateDomainObject";
fakeCustomer.Birthday = DateTime.Now;
// Get a DAO for communication
IBaseDAO<Customer> customerDao = Container.RequestForType <IBaseDAO<Customer>>();
// Persist the domiain object
customerDao.Create(fakeCustomer);
// Retrieve it in a new instance
Customer retrievedCustomer = customerDao.Read(fakeCustomer.Id);
// Compare values for equality
Assert.That(retrievedCustomer.Id.Equals(fakeCustomer.Id),
"Retrieved entity with Name: " + retrievedCustomer.Name + "(" + retrievedCustomer.Id + ")" +
"does not match with original entity with Name: " + fakeCustomer.Name + "(" + fakeCustomer.Id + ")");
}
Regardless of the poorly designed 'unit test' the test falls over with the following error:
ERROR [TestRunnerThread] SchemaUpdate [(null)]- could not complete schema update
System.NotSupportedException: Specified method is not supported.
Yes, I have all the required assemblies from the SQL Compact folder on my C:\ and in fact here is the strange part, in trying to find the source of this error, I of course debugged the unit test and stepped through the procedure line-by-line. On two occasions, the test has passed and the 'fakeCustomer' entity is persisted correctly in my database, however, 99% of the time, it will fail with the aforementioned error. The test has passed both when stepping through the test line-by-line and when simply running it from the Nunit GUI.
So, it seems like NHibernate can not imply the table structure of a SQL Compact database on its own, which is strange because I am using the ClassMap technique of FNHibernate and you'd think this would be sufficient enough to imply a table schema....every time the test is run.
Any help of guidance greatly appreciated. Thank you for your time.