Fluent NHibernate With Firebird

Well it works if a bit clunky first try by me. Thanks to some help on the Fluent NH email list and reading a couple docs, I got a really simplistic implementation based on the SQLLite version.

Config code:

   1:   public BootStrap()
   2:          {
   3:              _userName = "test";
   4:              _password = "test";
   5:              DbFile = "test.db";
   6:              ConnectionString = String.Format("ServerType=1;User={0};Password={1};Dialect=3;Database={2}", _userName, _password, DbFile);
   7:   
   8:              //setup firebird configuration
   9:              firebird = new FirebirdConfiguration();
  10:              firebirdConfig = Fluently.Configure().Database(
  11:                       firebird.ConnectionString(c => c
  12:                       .Is(ConnectionString)));
  13:          }

 

Create the Session:

   1:  public ISessionFactory CreateSessionFactory()
   2:          {
   3:              if (_sessionFactory == null)
   4:              {
   5:                  _sessionFactory = firebirdConfig.Mappings(m => m.FluentMappings.AddFromAssemblyOf<BootStrap>())
   6:                      .ExposeConfiguration(BuildSchema)
   7:                      .BuildSessionFactory();
   8:              }
   9:   
  10:              return _sessionFactory;
  11:          }

 

Build the Schema:

   1:  private void BuildSchema(Configuration config)
   2:          {
   3:              //quit if it alread exists
   4:              if (File.Exists(DbFile)) return;
   5:              
   6:              //user firebird to create the database
   7:              FbConnection.CreateDatabase(ConnectionString);
   8:   
   9:              // this NHibernate tool takes a configuration (with mapping info in)
  10:              // and exports a database schema from it
  11:              new SchemaExport(config)
  12:                  .Create(false, true);
  13:          }

 

Now the problem is I’m inserting test data each time test runs so there is an ever increasing number of records without getting cleaned up. So just have to manage the data state and it will work.  That said, SQLLite is the better option.  Firebird doesn’t support auto-increment keys and seems easier to manage.  Also, this sample code wouldn’t run on 64bit. It seems to have problems opening the process. Perhaps there is a 64 bit dll I should have been using though.

-j

 
June 25, 2009 22:46 by josh
E-mail | Permalink
blog comments powered by Disqus

Comments



about josh

another programmer blogging about his misadventures in writing code.

Contact

contact us for website & software consulting

Decide

decide on pragmatic solutions

Develop

develop your product together

Succeed

achieve your goals with our services