Sql Compact and Fluent NHibernate

I wanted a drop dead simple Fluent NHibernate connection to a Sql Compact (.sdf) file and was able to use:

?View Code CSHARP
private const string DbFile = "firstProgram.db";
 
return Fluently.Configure()
    .Database(MsSqlCeConfiguration.Standard.ShowSql().ConnectionString(c =>
        c.Is("data source=" + dbFile))
        )
    .Mappings(m =>
        m.FluentMappings.AddFromAssemblyOf<Program>()
        )
    .ExposeConfiguration(BuildSchema)
    .BuildSessionFactory();

Whereas the Sqlite connection was:

?View Code CSHARP
private const string DbFile = "firstProgram.db";
 
 return Fluently.Configure()
    .Database(SQLiteConfiguration.Standard
        .UsingFile(dbFile)
        )
    .Mappings(m =>
        m.FluentMappings.AddFromAssemblyOf<Program>()
        )
    .ExposeConfiguration(BuildSchema)
    .BuildSessionFactory();

When Googling I wasn’t able to find any samples so I hope to fill that void.

Tags:

One Response to “Sql Compact and Fluent NHibernate”

  1. Mark Says:

    Thanks Ben, this saved me some Googling!