Pregunta

Tengo una propiedad de tipo uint en mi entidad. Algo así como:

public class Enity
{
   public uint Count {get;set;}
}

Cuando intento persistir eso en la base de datos de SQL Server 2005, obtengo una excepción

  

Dialect no es compatible con DbType.UInt32

¿Cuál sería la forma más fácil de solucionar esto? Podría, por ejemplo, almacenarlo todo el tiempo en el DB. Solo que no sé cómo decírselo a NHibernate.

¿Fue útil?

Solución

La solución más limpia y más oficial probablemente sería escribir un tipo de usuario.

Tome un ejemplo, como este y adaptarlo. Si tiene muchos uint , vale la pena tener un tipo de usuario.

<property name="Prop" type="UIntUserType"/>

Otros consejos

No he probado esto, así que no estoy seguro de si esto funcionará para usted, pero podría intentar crear su propio dialecto y registrarlo en web.config / app.config

Clase de dialecto:

public class MyDialect:MsSql2005Dialect
{
    public MyDialect()
    {            
        RegisterColumnType(System.Data.DbType.UInt32, "bigint");            
    }
}

Web.config:

configuration>
 <configSections>
  <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
 </configSections>

                <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
   <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider, NHibernate</property>
   <property name="connection.connection_string">
    Server=127.0.0.1; Initial Catalog=thedatabase; Integrated Security=SSPI
   </property>
   <property name="dialect">MyDialect</property>
   <property name="current_session_context_class">managed_web</property>
  </session-factory>
 </hibernate-configuration>
    <!-- other app specific config follows -->

</configuration>
<property name="Prop" type="long"/>

Puede intentar agregar otra propiedad privada "espejo".

public class Enity
{
   public uint Count {get;set;}

   private long CountAsLong 
   { 
     get { return Convert.ToInt64(Count); } 
     set { Count = Convert.ToUInt(value); }
   }
}

<property name="CountAsLong" type="long"/>

Por supuesto, debe hacer esto solo si el mapeo no puede resolverlo.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top