DataStax Cassandra C# 驱动程序:WHERE IN (?) query with collection parameter
DataStax Cassandra C# driver: WHERE IN (?) query with collection parameter
我有以下 C# 代码:
IMapper mapper = new Mapper(session);
//...
var names = new [] {"n1", "n2", "n3"};
//Generation of question marks
var inStr = string.Join(",", names.Select(n=>"?"));
var users = mapper.Fetch<User>($"SELECT * FROM users WHERE name IN ({inStr})", names);
这种方法行之有效。
但也许有人知道更优雅的解决方案?
要在单个参数中提供值的动态列表,请在查询中使用 IN 运算符后跟不带括号的问号占位符。
例如:
var names = new [] {"n1", "n2", "n3"};
var users = mapper.Fetch<User>("SELECT * FROM users WHERE name IN ?", names);
我有以下 C# 代码:
IMapper mapper = new Mapper(session);
//...
var names = new [] {"n1", "n2", "n3"};
//Generation of question marks
var inStr = string.Join(",", names.Select(n=>"?"));
var users = mapper.Fetch<User>($"SELECT * FROM users WHERE name IN ({inStr})", names);
这种方法行之有效。 但也许有人知道更优雅的解决方案?
要在单个参数中提供值的动态列表,请在查询中使用 IN 运算符后跟不带括号的问号占位符。
例如:
var names = new [] {"n1", "n2", "n3"};
var users = mapper.Fetch<User>("SELECT * FROM users WHERE name IN ?", names);