数据类型的文本和nvarchar是等于运算符不兼容 [英] The data types text and nvarchar are incompatible in the equal to operator

查看:158
本文介绍了数据类型的文本和nvarchar是等于运算符不兼容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的code

ProductController.cs

public ActionResult Details(string id)
{
    product productx = productDB.products.Single(pr => pr.Product1 == id);
    return View(productx);


}

Details.aspx

    <td>
        <%-- : Html.ActionLink("Edit", "Edit", new { id=item.Id }) % --> 
        <%: Html.ActionLink("Details", "Details", new { id = item.Product1 })%>
    </td>

这是用什么来列举一些产品从SQL数据库的IM,每个产品都有一个链接到详细信息页面,显示有关它的更多信息。

this is what im using to list some products from a sql database, each product have a link to a Details page to show more informations about it

什么我试着是只把产品标签中的链接,让它显示类似的 www.mysite.com \\产品\\电池(不是ID)

what Im trying is to only put the product label in that link to let it show something like www.mysite.com\products\battery (not the id)

我已经想到这应该工作,但它引发的数据类型的文本和nvarchar是等于运算符不兼容。错误,
既不(PR =&GT; pr.Product1.Equals(ID));

I've imagined this should work, but it throw an The data types text and nvarchar are incompatible in the equal to operator. error and neither (pr => pr.Product1.Equals(id)); works

错误是明确的,林问我应该怎么做才能让这种方式工作?

the error is clear and Im asking how should I do to make it work this way ?

感谢

推荐答案

TEXT 在列SQL服务器被认为是大对象数据,因此不可转位/搜索。他们也是去precated。所以,实际上,问题是出在你的数据库,而不是在你的应用程序。

TEXT columns in SQL Server are considered Large Object data and therefore aren't indexable/searchable. They're also deprecated. So, actually, the problem is in your database, not in your application.

如果您更改列类型为 VARCHAR(最大),可以存储字符数据的相同数量,但不应有这个问题。然后,更新您的LINQ到SQL实体,你将不再获得此特定错误。

If you change the column type to a varchar(max), you can store the same amount of character data but shouldn't have this problem. Then, update your Linq to SQL entity, and you'll no longer get this particular error.

说了这么多......一列名为 ID 不应该 TEXT VARCHAR(最大),它应该是(唯一标识符 )将自动递增整数ID或GUID,所以你可能想重温你的数据库设计。但是,假设你有充分的理由的ID是任意大小的字符串值,上述变化将允许您对列进行筛选。

Having said that... a column named ID shouldn't be TEXT or varchar(max), it should be an auto-increment integer ID or a GUID (uniqueidentifier), so you might want to revisit your DB design. But assuming you have good reasons for IDs to be string values of arbitrary size, the above change will allow you to filter on the column.

这篇关于数据类型的文本和nvarchar是等于运算符不兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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