在Sqlite数据库中插入单条数据中带有double.NaN值报错 返回
SqlSugar
待处理
282
悬赏:5 飞吻
public class Price
{
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
public string Name { get; set; }
public double Value { get; set; }
}
public class Context
{
private string dbName;
private SqlSugarClient Client()
{
return new SqlSugarClient(new ConnectionConfig
{
ConnectionString = $"datasource={dbName}",
DbType = DbType.Sqlite,
IsAutoCloseConnection = true,
}
#if DEBUG
,
db =>
{
db.Aop.OnLogExecuting = (sql, pars) =>
{
Debug.WriteLine(UtilMethods.GetNativeSql(sql, pars));
};
}
#endif
);
}
public Context(string dbName)
{
this.dbName = dbName;
using (var db = Client())
{
db.CodeFirst.InitTables<Price>();
}
}
public void Test()
{
using (var db = Client())
{
var price = new Price
{
Name = "Test",
Value = double.NaN
};
db.Insertable(price).ExecuteCommand();
}
}
public void Test2()
{
using (var db = Client())
{
var priceList = new List<Price>
{
new Price
{
Name = "Test1",
Value = double.NaN
},
new Price
{
Name = "Test2",
Value = double.NaN
}
};
db.Insertable(priceList).ExecuteCommand();
}
}
}如上所示,Test2方法可顺利执行,但Test方法会报错。
System.InvalidOperationException:“Cannot store 'NaN' values.”