public void CreatingSchemaForStatedClassesInTempFile() { var types = new Types(typeof(FooRecord), typeof(BarRecord)); var fileName = "temp.sdf"; var persistenceConfigurer = new SqlCeDataServicesProvider(fileName).GetPersistenceConfigurer(true/*createDatabase*/); ((MsSqlCeConfiguration)persistenceConfigurer).ShowSql(); var sessionFactory = Fluently.Configure() .Database(persistenceConfigurer) .Mappings(m => m.AutoMappings.Add(AutoMap.Source(types))) .ExposeConfiguration(c => { // This is to work around what looks to be an issue in the NHibernate driver: // When inserting a row with IDENTITY column, the "SELET @@IDENTITY" statement // is issued as a separate command. By default, it is also issued in a separate // connection, which is not supported (returns NULL). c.SetProperty("connection.release_mode", "on_close"); new SchemaExport(c).Create(false, true); }) .BuildSessionFactory(); var session = sessionFactory.OpenSession(); session.Save(new FooRecord { Name = "Hello" }); session.Save(new BarRecord { Height = 3, Width = 4.5m }); session.Close(); session = sessionFactory.OpenSession(); var foos = session.CreateCriteria<FooRecord>().List(); Assert.That(foos.Count, Is.EqualTo(1)); Assert.That(foos, Has.All.Property("Name").EqualTo("Hello")); session.Close(); }
public static ISessionFactory CreateSessionFactory(string fileName, params Type[] types) { //var persistenceModel = AutoMap.Source(new Types(types)) // .Alterations(alt => AddAlterations(alt, types)) // .Conventions.AddFromAssemblyOf<DataModule>(); var persistenceModel = AbstractDataServicesProvider.CreatePersistenceModel(types.Select(t => new RecordBlueprint { TableName = "Test_" + t.Name, Type = t })); var persistenceConfigurer = new SqlCeDataServicesProvider(fileName).GetPersistenceConfigurer(true/*createDatabase*/); ((MsSqlCeConfiguration)persistenceConfigurer).ShowSql(); return Fluently.Configure() .Database(persistenceConfigurer) .Mappings(m => m.AutoMappings.Add(persistenceModel)) .ExposeConfiguration(c => { // This is to work around what looks to be an issue in the NHibernate driver: // When inserting a row with IDENTITY column, the "SELET @@IDENTITY" statement // is issued as a separate command. By default, it is also issued in a separate // connection, which is not supported (returns NULL). c.SetProperty("connection.release_mode", "on_close"); new SchemaExport(c).Create(false /*script*/, true /*export*/); }) .BuildSessionFactory(); }