|
sqlSugar.Insertable(_Data).ExecuteCommand(), this is running slowly, how to improve the speed using c# or lock the data to avoid SQLite error (5): database is locked?
If the sqlSugar.Insertable(_Data).ExecuteCommand() method is running slowly, there are several things you can try to improve its performance:
Use batch inserts: If you need to insert a large number of records, you can use batch inserts to improve performance. SqlSugar provides a Insertable<T>().AddRange(List<T>) method that allows you to insert a list of records in a single transaction.
For example:
List<Data> dataList = GetDataList();
sqlSugar.Insertable<Data>(dataList).ExecuteCommand();
This will insert all records in dataList in a single transaction, which can improve performance.
Use ExecuteCommandAsync() method: If you're running the ExecuteCommand() method on the UI thread, it can slow down the application's responsiveness. To avoid this, you can use the ExecuteCommandAsync() method instead, which runs the command on a background thread.
For example:
await sqlSugar.Insertable(_Data).ExecuteCommandAsync();
|
|