Does FluentNHibernate support SQL Server Compact Edition 4.0?

I know that they support SQL CE. I think they rise to 3.5 ??? I just downloaded CE 4.0 and I wanted to test it in my project, but I cannot configure it correctly in FluentNHibernate ...

If 4.0 is supported :

Which version do I need to download, and can someone give me an example of how to implement it?

+6
source share
1 answer

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 entity mappings must be added via AddFromAssembly. DatabaseFileName.sdf is the path and file name of the database file name. The path can be either absolute or relative to the application’s working directory (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 also work with CE 4.0: http://nhdatabasescopes.codeplex.com/SourceControl/changeset/view/f9e824a457e8#DatabaseScopes%2fMsSqlCeInFilePrivateScope.cs .

+10
source

Source: https://habr.com/ru/post/887080/


All Articles