I have a C# project which I have to develop for MS SQL Server, customer requirment, but since I do not have a license for it. Then I decide to go with NHibernate but NHibernate is relied on XML based configuration, which is not my preference, I research a little bit more, definitely I found out Fluent NHibernate is a good replacement for XML based configuration. I can map the entities with C# code that can reduce the errors prone in my code.
I use Firebird database in the development, though it can be used in production, I define the mapping as normal NHibernate (also Hibernate in Java). But when I try to build the configure for Fluent NHibernate, it's not the same as SQLite example, I try to fine the solution one by one from StackOverflow and the steps below can solved my problem.
I use Firebird database in the development, though it can be used in production, I define the mapping as normal NHibernate (also Hibernate in Java). But when I try to build the configure for Fluent NHibernate, it's not the same as SQLite example, I try to fine the solution one by one from StackOverflow and the steps below can solved my problem.
- Add the reference for NHibernate and its dependecies (NHibernate.dll, Iesi.Collections.dll)
- Add a reference for Fluent NHibernate (FluentNHibernate.dll), you can get it from nuget packacge manager
- Add a reference for Firebird dotnet connection (FirebirdSql.Data.FirebirdClient.dll)
- Follow the step in Fluent NHibernate wiki
- In the CreateSessionFactory adapt the code below
private static ISessionFactory CreateSessionFactory()Now you are ready to run your code
{
FbConnectionStringBuilder conStr = new FbConnectionStringBuilder();
conStr.Database = @"D:\<path to your firebird database>\xxx.fdb";
conStr.UserID = "SYSDBA";
conStr.Password = "masterkey";
//conStr.DataSource = "127.0.0.1";
conStr.Charset = "UTF8";
conStr.Dialect = 3;
conStr.ServerType = FbServerType.Default;
FirebirdConfiguration cfg = new FirebirdConfiguration()
.ConnectionString(conStr.ConnectionString)
.AdoNetBatchSize(100);
return Fluently.Configure()
.Database(cfg)
.Mappings(m => m.FluentMappings.AddFromAssemblyOf())
.ExposeConfiguration(BuildSchema)
.BuildSessionFactory();
}
ความคิดเห็น
แสดงความคิดเห็น