LINQ to SQL 中 Xml (XElement) 字段的常见问题

cite=LINQ to SQL FAQ – XML columns in SQL

LINQ to SQL 目前不支持包含 XElement 查询的 Expression 对象

However, LINQ to SQL does not appear to support ANY translations of XML queries on XElement to SQL – this mans that the following statement :

var filtered = from t in Table
where t.XmlCol.Descendants("SomeElement").Value == somevar
 select t

will fail at runtime as the LINQ-to-SQL parser is unable to translate on our XML data column XmlCol query into an Xpath.

LINQ to SQL 目前不支持由 XElement 内部变化引起的记录更新

A LINQ to SQL xml datatype column is represented as an XElement. If you modify this be careful as LINQ to SQL will not spot internal changes to XElement and save them to the database.

For example:

Dim myElement as XElement = Table.XMLdata
myElement.Value = "test"
db.SubmitChanges()

will not alter the instance XElement and so will not change the Table.XMLdata entry. The workaround for this is to write it back as a new element:

Dim myElement as XElement = Table.XMLdata
myElement.Value = "test"
Table.XMLdata = new XElement(myElement)
db.SubmitChanges()

 

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

ERROR: si-captcha.php plugin: GD image support not detected in PHP!

Contact your web host and ask them to enable GD image support for PHP.

ERROR: si-captcha.php plugin: imagepng function not detected in PHP!

Contact your web host and ask them to enable imagepng for PHP.

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据

Content is available under CC BY-SA 3.0 unless otherwise noted.