我想删除SQLite.Net-PCL包并想使用sqlite-net-pcl,因为我后来发现它SQLite.Net-PCL
没有被官方维护。
我的 Xamarin 项目中有存储GUID
为字符串类型主键的表。我有来自服务器的记录列表,目前使用InsertOrReplaceAll
方法插入新记录并更新现有记录,所有这些都基于我的GUID
主键。
现在,sqlite-net-pcl
没有InsertOrReplaceAll
方法,而是只有InsertAll
&UpdateAll
方法。Microsoft msdn Link表示检查主键是否具有可用值,并根据该值决定是否必须插入或更新记录。
但是,我有一种情况,主键值总是List
在插入或更新对象之前预先设置在 中,并且不想循环检查记录是否存在超过 500 条记录。
在这种情况下如何一次插入或替换我的所有记录?
考虑以下示例来理解这种情况:
using (var conn = new DBConnectionService().GetConnection())
{
List<ENTEmployee> employees = new List<ENTEmployee>()
{
new ENTEmployee(){ Id = "b977ec04-3bd7-4691-b4eb-ef47ed6796fd", FullName = "AAA BBB", Salary = 15000 },
new ENTEmployee(){ Id = "c670a3e2-b13f-42b3-849c-fd792ebfd103", FullName = "BBB BBB", Salary = 16000 },
new ENTEmployee(){ Id = "d961c33c-0244-48dc-8e10-f4f012386eb6", FullName = "CCC BBB", Salary = 17000 },
new ENTEmployee(){ Id = "35be4508-ff93-4be8-983f-d4908bcc592d", FullName = "DDD BBB", Salary = 18000 },
new ENTEmployee(){ Id = "0875549c-d06c-4983-b89a-edf81b6aa70d", FullName = "EEE BBB", Salary = 19000 },
};
var insertResult = conn.InsertAll(employees);
//Updated Record
employees[0].FullName = "AAA Updated";
employees[0].Salary = 12300;
//New Records
employees.Add(new ENTEmployee() { Id = "87f48ecf-715c-4327-9ef3-11712ba4a120", FullName = "FFF BBB", Salary = 20000 });
employees.Add(new ENTEmployee() { Id = "85f53888-b1e9-460c-8d79-88010f143bcf", FullName = "GGG BBB", Salary = 21000 });
//Now here,
//How to decide which records to be inserted and which records to be updated for List employees?
}