Note that there are some explanatory texts on larger screens.

plurals
  1. POFluent Nhibernate with SQL Compact: Schema Issue
    primarykey
    data
    text
    <p>Good evening people,</p> <p>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:</p> <pre><code> 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 =&gt; m.FluentMappings.AddFromAssembly(configuration.MappingAssembly)) .ExposeConfiguration(x =&gt; new SchemaUpdate(x).Execute(false, true)) .BuildSessionFactory(); } </code></pre> <p>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.</p> <p>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.</p> <p>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.</p> <p>Now I have the following unit test: </p> <pre><code>[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&lt;Customer&gt; customerDao = Container.RequestForType &lt;IBaseDAO&lt;Customer&gt;&gt;(); // 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 + ")"); } </code></pre> <p>Regardless of the poorly designed 'unit test' the test falls over with the following error:</p> <pre><code>ERROR [TestRunnerThread] SchemaUpdate [(null)]- could not complete schema update System.NotSupportedException: Specified method is not supported. </code></pre> <p>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.</p> <p>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.</p> <p>Any help of guidance greatly appreciated. Thank you for your time.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload