Created
December 7, 2012 06:57
-
-
Save jonathascosta/4231336 to your computer and use it in GitHub Desktop.
Tipo de suporte a colunas S/N no Oracle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Data; | |
| using NHibernate; | |
| using NHibernate.SqlTypes; | |
| using NHibernate.UserTypes; | |
| namespace Framework.DataAccess.NHibernate.UserTypes | |
| { | |
| [Serializable] | |
| public class SimNaoType : IUserType | |
| { | |
| public bool IsMutable | |
| { | |
| get { return false; } | |
| } | |
| public Type ReturnedType | |
| { | |
| get { return typeof(SimNaoType); } | |
| } | |
| public SqlType[] SqlTypes | |
| { | |
| get { return new[] { NHibernateUtil.String.SqlType }; } | |
| } | |
| public object NullSafeGet(IDataReader rs, string[] names, object owner) | |
| { | |
| var obj = NHibernateUtil.String.NullSafeGet(rs, names[0]); | |
| if (obj == null) return null; | |
| var simNao = (string)obj; | |
| if (simNao != "S" && simNao != "N") | |
| throw new Exception(string.Format("Expected data to be 'S' or 'N' but was '{0}'.", simNao)); | |
| return simNao == "S"; | |
| } | |
| public void NullSafeSet(IDbCommand cmd, object value, int index) | |
| { | |
| if (value == null) | |
| { | |
| ((IDataParameter)cmd.Parameters[index]).Value = DBNull.Value; | |
| } | |
| else | |
| { | |
| var sim = (bool)value; | |
| ((IDataParameter)cmd.Parameters[index]).Value = sim ? "S" : "N"; | |
| } | |
| } | |
| public object DeepCopy(object value) | |
| { | |
| return value; | |
| } | |
| public object Replace(object original, object target, object owner) | |
| { | |
| return original; | |
| } | |
| public object Assemble(object cached, object owner) | |
| { | |
| return cached; | |
| } | |
| public object Disassemble(object value) | |
| { | |
| return value; | |
| } | |
| public new bool Equals(object x, object y) | |
| { | |
| if (ReferenceEquals(x, y)) return true; | |
| if (x == null || y == null) return false; | |
| return x.Equals(y); | |
| } | |
| public int GetHashCode(object x) | |
| { | |
| return x == null ? typeof(bool).GetHashCode() + 473 : x.GetHashCode(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment