Arash
Arash

Reputation: 156

How to set encoding in fluent NHibernate?

I have created my database by this sql query: ("CREATE DATABASE " + DBName + " DEFAULT CHARSET=utf8 COLLATE=utf8_persian_ci", connection)

And I have this fluent configuration:

Fluently.Configure()
                     .Database(MySQLConfiguration.Standard.ConnectionString(c => c.Server(server)
                        .Database(DBName).Username(username).Password(password)))
                     .Mappings(m => m.FluentMappings.AddFromAssemblyOf<Program>())
                     .BuildSessionFactory();

How can I set NHibernate encoding in this configuration? or how can I set my mappings encoding?

I want to this because when I want to select with a property which has UTF8 encoding NHibernate sql will include ??????? in strings with encoding

Upvotes: 3

Views: 3248

Answers (2)

Tom
Tom

Reputation: 56

var mysqlconf = MySQLConfiguration.Standard
.ConnectionString(c => c.Is("Server=srv;Database=db;User=dev;Password=pass;CharSet=utf8"));

return Fluently.Configure().Database(mysqlconf).Mappings(m =>
    m.FluentMappings.AddFromAssemblyOf<Program>()).BuildSessionFactory();

Upvotes: 4

Dariusz Tarczynski
Dariusz Tarczynski

Reputation: 16721

Setting the database encoding is not related to Fluent NHibernate. Check your connection string, it should be like:

Server=myServerAddress;Database=myDataBase;Uid=user;Pwd=passw; CharSet=UTF8;

Upvotes: 4

Related Questions