执行Insert方法,返回受影响行数报错
DBConst.FSQL.Insert<sys_info>(data).ExecuteAffrows();
System.MissingFieldException
HResult=0x80131511
Message=Field not found: 'FreeSql.Internal.CommonProvider.InsertProvider1._batchValuesLimit'. Source=FreeSql.Provider.Sqlite StackTrace: 在 FreeSql.Sqlite.Curd.SqliteInsert
1.ExecuteAffrows()
原因:没有引用FreeSql.Provider.Sqlite,查询不受影响,但是插入和修改的时候会报错
解决方案:实体类sys_info所在项目必须引用FreeSql和FreeSql.Provider.Sqlite
两个包版本不一样可能会引用失败,卸载NuGet包,两个包重新引用,版本就一样了,不会报错
public IFreeSql FSQL { get; set; }
public string MySQLConnectionString { get; set; }//连接字符串
public void Init(string dbfile)
{
if (FSQL == null)
{
string connstring = GetConntionString(dbfile);
MySQLConnectionString = connstring;
DBConst.Current.FSQL = new FreeSql.FreeSqlBuilder()
.UseConnectionString(FreeSql.DataType.Sqlite, MySQLConnectionString)
.UseAutoSyncStructure(false)
.UseMonitorCommand(cmd => Logs.DbInfo(“SQLMonitor:” + cmd.CommandText))
.Build(); //请务必定义成 Singleton 单例模式
}
}
public static bool Del(string id)
{
var change = DBConst.FSQL.Delete<t_table_test>().Where(" id=@zbid and isdel=@isdel", new { id = id, isdel = 1}).ExecuteAffrows();
return change > 0;
}