我使用Dapper-Extensions将数据拉取并推送到数据库
我使用unsigned int
id 作为我在数据库和类中的主键。我的课看起来像这样
public class Product {
[Column("id")]
public uint Id { get; set; }
}
我的映射器类看起来像这样
public class ProductMap : ClassMapper<Product>
{
public ProductMap()
{
Table("Product");
this.Map(typeof(Product).GetProperty("Id")).Key(KeyType.Identity);
}
}
我像这样插入数据
using DapperExtensions;
public virtual uint Add(T item)
{
using (conn)
{
return Convert.ToUInt32(conn.Insert<T>(item)); // System.ArgumentException: 'Object of type 'System.Int32' cannot be converted to type 'System.UInt32'.'`
}
}
当我将数据插入数据库时,项目被插入数据库没有问题,但是插入函数不断返回以下错误:
'System.Int32' 类型的对象无法转换为'System.UInt32' 类型。
我怎么可能解决这个问题?