Created
August 12, 2013 11:31
-
-
Save tarasn/6210101 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Reflection; | |
| using FluentNHibernate; | |
| using FluentNHibernate.Cfg.Db; | |
| using NHibernate; | |
| using NHibernate.Cfg; | |
| using NHibernate.Tool.hbm2ddl; | |
| namespace NHibernateExperiments.Fluent | |
| { | |
| public class InMemoryDatabaseFluent | |
| { | |
| private Configuration _configuration; | |
| public ISession Session { get; private set; } | |
| public InMemoryDatabaseFluent() | |
| { | |
| var sessionFactory = CreateSessionFactory(); | |
| Session = sessionFactory.OpenSession(); | |
| BuildSchema(); | |
| } | |
| private void BuildSchema() | |
| { | |
| var export = new SchemaExport(_configuration); | |
| export.Execute(true, true, false, Session.Connection, null); | |
| } | |
| private ISessionFactory CreateSessionFactory() | |
| { | |
| var connectionString = string.Format("data source=:memory:"); | |
| IPersistenceConfigurer persistenceConfigurer = SQLiteConfiguration.Standard | |
| .ShowSql() | |
| .ConnectionString(connectionString); | |
| _configuration = persistenceConfigurer | |
| .ConfigureProperties(new Configuration()); | |
| var persistenceModel = new PersistenceModel(); | |
| var assembly = Assembly.GetAssembly(typeof(InMemoryDatabaseFluent)); | |
| persistenceModel.AddMappingsFromAssembly(assembly); | |
| persistenceModel.Configure(_configuration); | |
| return _configuration.BuildSessionFactory(); | |
| } | |
| public void Dispose() | |
| { | |
| Session.Dispose(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment