简体   繁体   中英

Nhibernate Found: integer, Expected INT

I get an exception:

NHibernate.HibernateException: Wrong column type in main_Command for column Id.
Found: integer, Expected INT

The mapping is:

<id name="Id" type="int">
  <generator class="identity" />
</id>

And the class property is:

public virtual int Id { get; set; }

Checking the NHibernate source for the SQLite Dialect and finding an answer to a similar question. It looks like all signed integer types don't map to INTEGER as is required for the SQLite Auto Increment column.

RegisterColumnType(DbType.Int16, "SMALLINT");
RegisterColumnType(DbType.Int32, "INT");
RegisterColumnType(DbType.Int64, "BIGINT");

But the good news is that unsigned ints do map to INTEGER .

RegisterColumnType(DbType.UInt16, "INTEGER");
RegisterColumnType(DbType.UInt32, "INTEGER");
RegisterColumnType(DbType.UInt64, "INTEGER");

Therefore, please try the following mapping:

<id name="Id" type="UInt32">
  <generator class="identity" />
</id>

With the corresponding change to you class:

public virtual UInt32 Id { get; set; }

I think your type is wrong (but I could be wrong), according to this article is taken from NHibernate in Action from Manning Publications.

.NET primitive mapping types

Mapping Type  .NET Type      System.Data.DbType 
   Int16     System.Int16    DbType.Int16
   Int32     System.Int32    DbType.Int32
   Int64     System.Int64    DbType.Int64

Try using type='Int32' or removing it altogether

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM