我有一个 UDT 列表,例如:
create table MyTable
{
...
stuff list<frozen<MyType>>,
...
}
在我的客户端代码中,我想将一个元素附加到“stuff”。理想情况下,我想做以下(或类似的事情):
this.Mapper<MyTable>("SET stuff = stuff + [?] WHERE id = ?", mytype, id);
不幸的是,此操作失败并出现以下错误:
Invalid list literal for stuff: bind variables are not supported inside collection literals
我可以通过将 mytype 转换为 json 来使其工作,例如:
var stuffAsJson = stuff.ToJson();
var update = string.Format("SET stuff = stuff + [{0}] WHERE id = ?", commentAsJson);
this.Mapper.Update<MyTable>(update, stuffAsJson, id);
然而,知道如何将对象转换为 json 是很棘手的(例如,不需要用双引号引用字符,而是需要用单引号引用它们)。
因此,我希望有更好的方法将类型元素添加到列表中。
感谢您的帮助,
埃里克
正确的 CQL 语法是:
UPDATE table1 SET stuff = stuff + ? WHERE id = ?
它需要一个类型的参数list<MyType>
。在你的情况下,它将是:
this.Mapper<MyTable>(
"SET stuff = stuff + ? WHERE id = ?", new List<MyType> {myItem}, id);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)