user47589
user47589

Reputation:

Fluent NHibernate - mapping a CultureInfo object?

I have a class like so:

public class User
{
    public CultureInfo Culture {get;set;}
}

I have my mapping class like so:

public class UserMap : ClassMap<User>
{
    public UserMap()
    {
        ??
    }
}

I would like to persist this users culture info to and from the database as the culture string (such as "en-US"). I'm a rookie when it comes to NHibernate and Fluent NHibernate. How do I tell the mapper to use the culture string when persisting and to create the culture object when retrieving?

Upvotes: 4

Views: 388

Answers (1)

svick
svick

Reputation: 244767

It's not as easy as telling NHibernate to save the class as a string, you have to provide the mapping that works the other way too. To do that, implement IUserType as described in this article.

You can then map it as Map(x => x.Culture).CustomType<CultureType>(), assuming your IUserType implementation is called CultureType.

Upvotes: 5

Related Questions