Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does FluentNHibernate Support SQL Server Compact Edition 4.0?

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?

like image 865
Nautic20 Avatar asked May 02 '11 00:05

Nautic20


People also ask

What is Microsoft SQL Server Compact 4 used for?

Microsoft SQL Server Compact 4.0 is a free, embedded database that software developers can use for building ASP.NET websites and Windows desktop applications.

What is the latest version of SQL Server Compact?

The latest, and last, release is the SQL Server Compact 4.0. As of February 2013 SQL Server Compact Edition had been deprecated; no new versions or updates are planned, although Microsoft will continue to support until July 2021.

How do I open Microsoft SQL Server Compact Edition?

(1) Open SQL Server Management Studio, or if it's running select File -> Connect Object Explorer... (2) In the Connect to Server dialog change Server type to SQL Server Compact Edition (3) From the Database file dropdown select <Browse for more...> (4) Open your SDF file.


1 Answers

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.

like image 152
Jakub Linhart Avatar answered Sep 24 '22 03:09

Jakub Linhart