[英]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: 并且class属性是:
public virtual int Id { get; set; }
Checking the NHibernate source for the SQLite Dialect and finding an answer to a similar question. 检查用于SQLite方言的NHibernate源,并找到类似问题的答案。 It looks like all signed integer types don't map to
INTEGER
as is required for the SQLite Auto Increment column. 看起来所有带符号的整数类型都不像SQLite自动增量列所要求的那样映射到
INTEGER
。
RegisterColumnType(DbType.Int16, "SMALLINT");
RegisterColumnType(DbType.Int32, "INT");
RegisterColumnType(DbType.Int64, "BIGINT");
But the good news is that unsigned ints do map to INTEGER
. 但是好消息是,未签名的int确实映射到
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. 我觉得你的类型是错误的(但我可能是错的),根据该文章是从NHibernate的采取行动从曼宁出版物。
.NET primitive mapping types .NET基本映射类型
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 尝试使用
type='Int32'
或将其完全删除
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.