开发者

Can any one provide me LINQ to update data inside xml column?

I have a table Table1 has columns ID (int) and XMLTEXT of xml type Can any one provide me LINQ query which is equivalent to below sql query

Update Table1 set XMLTEXT .modify('delete (/root/child1/child2)') 开发者_高级运维 where ID=1001


In Linq2SQL, something like this should work.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜