开发者

Fluent NHibernate - mapping a CultureInfo object?

开发者 https://www.devze.com 2023-03-27 12:38 出处:网络
I have a class like so: public class User { public CultureInfo Culture {get;set;} } I have my mapping class like so:

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 开发者_StackOverflow社区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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消