简体   繁体   English

如何在 sqlite-net 中提供一个列表作为我的参数

[英]How do I provide a list as my parameter in sqlite-net

I am building a Xamarin Forms application and using Sqlite-net .我正在构建一个 Xamarin Forms 应用程序并使用Sqlite-net I want to run a delete query that deletes all records that have a field in a list so something like below:我想运行一个删除查询,删除列表中包含字段的所有记录,如下所示:

//usersToDelete is a list of Objects each representing a user.
List<int> idsToDelete = new List<int>();
foreach (var user in usersToDelete)
{
    idsToDelete.Add(user.Id);
}
string dbQuery = "DELETE FROM Users WHERE Id IN (?)";
var deleteCount = await LocalDatabaseConnection.ExecuteAsync(dbQuery, idsToDelete);

This does not work for me.这对我不起作用。 It fails with the error Cannot store type: System.Collections.Generic.List1[System.Int32] .它失败并出现错误 Cannot store type: System.Collections.Generic.List1[System.Int32] Does this mean I have build the string in code in palce of "(?)"?这是否意味着我已经在“(?)”的代码中构建了字符串? Or is there some way to provide this as a parameter.或者有什么方法可以将其作为参数提供。

try this尝试这个

var utd= usersToDelete.Select(i=> i.Id.ToString()).ToArray();
string ids=string.Join(",",utd);
string dbQuery = $"DELETE FROM Users WHERE Id IN ({ids})";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM