2

i am using NHibernate together with a Firebird Database and are not sure if the String-Types are mapped correctly. In .NET a String-Type is normally UTF16 encoded. In Firebird i have defined my Domain wie Character Set UTF8.

So if i have this Domain-Class:

public class Project
{
    public virtual Int64 ID { get; set; }
    public virtual String Name { get; set; }
}

and this NHibernate Mapping:

<class name="Project">
<id name="Id">
  <generator class="sequence">
    <param name="sequence">MY_GEN</param>
  </generator>
</id>
<property name="Name"/>
</class>

Does NHibernate automatically converts my System.String to a Firebird UTF8 String in this case? It seems to be ok in the database. But i am not sure about the handling in NHibernate.

1
  • 4
    It is misleading to say "In .NET a String-Type is normally UTF16 encoded", as encoding refers to the serialized form. A string is not that; a string is raw Unicode code-points - quite different. Normally, the ADO.NET driver (or other driver) will be responsible for this step - in most cases I would not expect the ORM tool to have anything to do with encoding. Commented Sep 15, 2012 at 9:59

1 Answer 1

1

The default string type for NHibernate saves the data using DbType.String (which is a Unicode string). Firebird will encode the unicode string in UTF8 for you.

The alternative (without getting into custom types) would be to specify an AnsiString type which would also work with UTF8 if all you used was ASCII characters.

Since you're not specifying the type, NHibernate will use it's StringType and it will work properly.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.