Skip to content

How to persist/save and read a ValueObject in the database using NHibernate? #537

Answered by vkhorikov
rklec asked this question in Q&A
Discussion options

You must be logged in to vote

Use the IUserType feature from NHibernate. Here are some examples from one of my projects.

    public abstract class UserType<TUserType, TUnderlyingType> : IUserType
    {
        public new bool Equals(object x, object y)
        {
            if (x == null && y == null)
                return true;

            if (x == null || y == null)
                return false;

            return x.Equals(y);
        }


        public object NullSafeGet(DbDataReader rs, string[] names, ISessionImplementor session, object owner)
        {
            object value = GetNHibernateType().NullSafeGet(rs, names, session, owner);
            return WrapValue(value);
        }


        private object W…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@rklec
Comment options

Answer selected by rklec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants