ข้ามไปที่เนื้อหาหลัก

Fluent NHibernate Configuration

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.


  • 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()
        {
            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();
        }
Now you are ready to run your code

ความคิดเห็น

โพสต์ยอดนิยมจากบล็อกนี้

หมดหวังกับรายการทีวีในประเทศไทย

ไม่ได้เขียน Blog มานานสกิลด้านเขียนไม่รู้จะยังดีเหมือนเดิมมั้ยนะครับ (หัวข้อก็จะ clickbait  ตามแนว Content ยุคใหม่) จริงๆ แล้ว คิดจะเขียนมาตั้งนานแล้วแต่ไม่รู้จะเขียนอะไร พอดีวันนี้อ่านเจอโพสต์ของเพื่อนในเฟสบุ๊คที่แชร์มา หัวข้อประมาณว่า ประเทศไทยมีความพยายามทำให้คนโง่ลง คือผมก็ติดตามข่าวมาเรื่อยๆ ช่วงไปอยู่จีนก็ยังติดตามอยู่ แต่มีความรู้สึกว่าข่าวของประเทศเรากับประเทศจีนนี่คือคนละขั้วเลย ที่จีนข่าวส่วนใหญ่จะเป็นข่าวที่ค่อนข้างมีสาระ และไม่มีข่าวงมงาย น่าจะเนื่องมาจากกฎหมายของประเทศไทยที่ค่อนข้างคุมเข้มกับสื่อ ย้อนกลับมาที่ไทย ประเทศเราไม่มีกฎหมายคุมเข้มสื่อเหมือนประเทศจีนขนาดนั้น สื่อประเทศเราค่อนข้างมีอิสระในการนำเสนอ แต่หลังๆ มานี่ผมเห็นแต่ข่าวอาชญากรรม หรือข่าวให้หวยซะส่วนใหญ่ ก็เข้าใจว่าต้องการยอดผู้ชม แต่การที่สื่อนำเสนอแบบนั้นนี่ไม่แน่ใจว่าจะดีต่ออนาคตประเทศชาติหรือไม่นะครับ คนดูข่าวเพื่อจะรอเลขเอาไปซื้อหวย ไม่แน่ใจว่าสนใจอะไรมากกว่าระหว่างหวยกับข่าว ตอนจะมีกฎหมายหวยออนไลน์ก็เห็นออกมาต่อต้านบอกมอมเมาประชาชน แต่สิ่งที่สื่อกำลังนำเสนออยู่นั้นมันย้อนแย้งในตัวเองชอบกล และ

Standalone MySQL setup

Currently I am learning Spring Boot. I follow some tutorials but there is a part requires to use DBMS. So I decide to use MySQL as a database. But I don't want to install it as as service neither install with Windows installer. I decide to download an archive version to run it as standalone application. I expect it will be ready to use as the installer version but it is not as easy as I think. The first thing you have to do after extract the archive file is to copy my-default.ini to my.ini Open my.ini with notepad or text editor that you like, edit these lines as show below basedir = X:/<pat to your mysql folderh>/mysql-5.7.9-winx64 datadir = X:/<pat to your mysql folderh>/mysql-5.7.9-winx64/data Important!  Don't forget to create the folder data to the path they you refer in datadir  Second you have to mysql bin directory and then input the following command in command prompt mysqld --initialize --console --console is optional to see the verbose in