SQL Server上的NText,文本和图像的LINQ问题 [英] LINQ problems with NText, Text and Image on SQL server

查看:149
本文介绍了SQL Server上的NText,文本和图像的LINQ问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

道歉,因为这不是一个问题,而是一个解决方案-但经过大量搜索才能找到答案,而google并没有太大帮助,所以我想通过提供以下方式回馈社区错误和解决方案,以帮助将来的Google员工.

Apologies up front, because this isn't a question but a solution - but it took a lot of searching to find out the answer and google wasn't much help, so I wanted to give something back to the community by providing the error and the solution to help future googlers.

使用LINQ to SQL时,(第二次)将更改提交到数据表时遇到问题.第一次提交所有更改都可以,第二次提交更改时,我收到一条SQL异常,内容为:

When using LINQ to SQL, I ran into a problem when submitting changes (the second time) to a data table. The first time I submit changes all is OK, the second time I submit changes I recieved a SQL exception which said:

"The text, ntext, and image data types cannot be compared or sorted, 
 except when using IS NULL or LIKE operator"

当我调用SubmitChanges()时引发了异常,但是由于LINQ的延迟加载,它实际上是在我调用Refresh(RefreshMode.KeepCurrentValues,myObject)的前一行中出现的.

The exception was thrown when I was calling SubmitChanges(), but because of the lazy loading of LINQ it actually arose in the previous line when I was calling Refresh(RefreshMode.KeepCurrentValues, myObject).

推荐答案

问题是刷新模式试图将当前值与所有字段的数据库版本进行比较,并且SQL不支持这种比较文本,ntext和image列(至少在SQL Server 2000上不是).

The problem is that the Refresh mode is attempting to compare the current with the database version of all the fields, and SQL doesn't support that kind of comparison text, ntext and image columns (at least not on SQL Server 2000).

解决方案是将以下属性添加到您的列定义中

The solution is to add the following attribute to your column definition

UpdateCheck = UpdateCheck.Never

例如

[Column(DbType = "NText", CanBeNull = true, UpdateCheck = UpdateCheck.Never)]

然后,刷新模式可以正常工作,SubmitChanges不会有任何其他问题.

Then the Refresh mode works OK and SubmitChanges doesn't have any further problems.

这篇关于SQL Server上的NText,文本和图像的LINQ问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆