【问题标题】:Can any one provide me LINQ to update data inside xml column?任何人都可以为我提供 LINQ 来更新 xml 列中的数据吗?
【发布时间】: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


【解决方案1】:

在 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();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-01
    • 2020-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多