在表中使用LINQ-TO-SQL更新一个包含XML数据的列



我正在使用linq-to-sql创建和维护SQL中的表,其中包含发送到另一个应用程序及其相应响应的XML消息。表中的每一行都包含请求消息或响应消息的详细信息以及关联消息的ID(在响应消息的情况下,请求消息的ID,反之亦然)。

这一切都很好,直到我尝试更新包含请求消息行中关联响应消息的ID的列。为此,我正在使用表格的代码:

using (var MessageStore = new MessageStore(CONNECTION_STRING))
{
     // Get the Request message with the specified ID
     var Request = MessageStore.XMLMessages.SingleOrDefault(X => X.Id == RequestId);                  
     // Update the row with the ID of the associated response message
     if (Request != null)
     {
          Request.LinkedMessageId = ResponseId;
          MessageStore.SubmitChanges();
     }
}

但是,the the the clitchanges呼叫抛出一个例外:

SQL Server does not handle comparison of NText, Text, Xml, or Image data types.

看起来,SQL将更新消息中的XML数据与原始数据进行了比较,但我不需要。有什么方法可以在行中更新行中的其他一些列而无需比较XML数据?我尝试使用匿名类型,但仅读取这些类型,因此我无法更新值然后存储。

任何建议都将不胜感激。

在发布问题后大约5分钟找到答案!诀窍是将UpdateCheck设置为"永远不要在关联的属性上"

[Column(DbType = "Xml NOT NULL", CanBeNull = false, UpdateCheck = UpdateCheck.Never)]
public XElement MessageText { get; set; }

相关内容

最新更新