【发布时间】:2010-12-03 18:11:33
【问题描述】:
我有一个表 Table1 有列 ID (int) 和 xml 类型的 XMLTEXT 谁能给我提供相当于下面sql查询的LINQ查询
更新 Table1 设置 XMLTEXT .modify('delete (/root/child1/child2)') 其中 ID=1001
【问题讨论】:
标签: linq-to-sql
我有一个表 Table1 有列 ID (int) 和 xml 类型的 XMLTEXT 谁能给我提供相当于下面sql查询的LINQ查询
更新 Table1 设置 XMLTEXT .modify('delete (/root/child1/child2)') 其中 ID=1001
【问题讨论】:
标签: linq-to-sql
在 Linq2SQL 中,这样的东西应该可以工作。
long ProductID = 1;
ORM.Table1 p = context.Table1s.Where(o => o.ID == ProductID).FirstOrDefault();
if(p != null) {
p.XMLTEXTe.Element("child2").Remove();
// Need to do this so Linq picks up on the data change
// as it doesnt implement the correct XElement data changed event handler
// and thus won't submit the changes made if you dont do the reassignment!
p.XMLTEXT = new XElement(p.XMLTEXT);
context.SubmitChanges();
}
【讨论】: