Reputation: 215
I know they support SQL CE. I think they go up to 3.5??? I just downloaded CE 4.0 and I wanted to test it out in my project but I can't get it configured right in FluentNHibernate...
If 4.0 is supported:
What version do I have to download and could someone give me an example of how to implement it?
Upvotes: 6
Views: 4362
Reputation: 4072
FNH supports CE 4.0, try this configuration:
var config = Fluently.Configure()
.Database(MsSqlCeConfiguration.Standard.ConnectionString("Data Source=DatabaseFileName.sdf"))
.Mappings(m =>
{
m.FluentMappings.AddFromAssembly(typeof(Entity).Assembly);
})
.BuildConfiguration();
Assemblies with your entity mappings should be added via AddFromAssembly. DatabaseFileName.sdf is path and file name of the database file name. Path can be or absolute or relative to working directory of the application (windows application: System.AppDomain.CurrentDomain.BaseDirectory; web application: System.AppDomain.CurrentDomain.RelativeSearchPath).
Tested on FNH1.0, NH2.1 and SQL Server CE 4.0.
EDIT: The database file must be created by the database engine:
using (var engine = new SqlCeEngine(connectionString))
{
engine.CreateDatabase();
}
Here is an example for CE 3.5 but it should work with CE 4.0 as well: http://nhdatabasescopes.codeplex.com/SourceControl/changeset/view/f9e824a457e8#DatabaseScopes%2fMsSqlCeInFilePrivateScope.cs.
Upvotes: 10