Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fluent NHibernate failing to create session factory with SQLCE

I'm trying out my very first project with Fluent NHibernate (any NHibernate flavor for that matter). I've been unable to get past the point of creating a Session Factory object as I'm running in to the following exception:

InnerException: NHibernate.HibernateException
                      Message=The IDbCommand and IDbConnection implementation in the assembly System.Data.SqlServerCe could not be found. Ensure that the assembly System.Data.SqlServerCe is located in the application directory or in the Global Assembly Cache. If the assembly is in the GAC, use <qualifyAssembly/> element in the application configuration file to specify the full name of the assembly.
                      Source=NHibernate
                      StackTrace:
                           at NHibernate.Driver.ReflectionBasedDriver..ctor(String driverAssemblyName, String connectionTypeName, String commandTypeName)
                           at NHibernate.Driver.SqlServerCeDriver..ctor()
                      InnerException: 

I'm using the latest FluentNHibernate binaries. VS 2010, on Window 7 x64. I've set the System.Data.SqlServerCe assembly to "Copy Local" changed the project's target platform to x86.

The fluent config is:

var config  = Fluently.Configure()
                        .Database(MsSqlCeConfiguration.Standard.ShowSql().ConnectionString(cnxString))
                        .Mappings(m => m.FluentMappings.AddFromAssemblyOf<SyncContract>());

if (!File.Exists(dbPath))
{
     var engine = new System.Data.SqlServerCe.SqlCeEngine(cnxString);
     engine.CreateDatabase();

     config.ExposeConfiguration(c => new SchemaExport(c).Create(false, true));
}
return config;

Note: engine.CreateDatabase() works fine.

Any help/ideas please?

like image 389
Sameera Avatar asked Nov 29 '10 06:11

Sameera


1 Answers

Ok, figured it out.

Copy Local didn't apply to the test project I was using and consequently, the libs didn't get copied to the bin folder of the test project. Added all the libraries as references to the test project and set copy local on them to get this to work.

like image 152
Sameera Avatar answered Nov 13 '22 17:11

Sameera