varchar(最大) + LINQ 到 SQL

发布于 2024-09-25 04:01:12 字数 930 浏览 1 评论 0原文

我有一个 varchar(max) 列,我正在尝试读取该列,但该字段被截断为 4,000 个字符。我见过类似的问题,但是他们在sql这边。

我需要做什么才能获得整个字段?

例如:

using (DataContext dc = new DataContext())
{
    var foo = dc.foos.First();
    if (foo.Formula2.Length > 4000)
    {
        Console.WriteLine("success!");
    }
}

我尝试过 设置 TextSize 之类的东西,但它没有'没有区别。:

dc.ExecuteCommand("SET TEXTSIZE 100000;");
var foo = dc.foos.First();

更新:

服务器数据类型是 varchar(max)。有问题的字段是公式2: alt text

如果我尝试将类型更改为不同的类型,例如对象,我会收到消息“DbType 之间的映射”不支持“t_PriceFormula”类型的“Formula2”列中的“VarChar(MAX)”和类型“System.Object”。'

有什么建议吗?

I've got a varchar(max) column I'm trying to read but the field is being truncated at 4,000 characters. I've seen similar questions, but they are on the sql side.

What do I need to do to get the entire field?

Eg:

using (DataContext dc = new DataContext())
{
    var foo = dc.foos.First();
    if (foo.Formula2.Length > 4000)
    {
        Console.WriteLine("success!");
    }
}

I've tried things like setting TextSize but it didn't make a difference.:

dc.ExecuteCommand("SET TEXTSIZE 100000;");
var foo = dc.foos.First();

UPDATE:

The server data type is varchar(max). The field in question is formula2:
alt text

If I try and change the type to something different like Object, I get message 'Mapping between DbType 'VarChar(MAX)' and Type 'System.Object' in Column 'Formula2' of Type 't_PriceFormula' is not supported.'

Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

画中仙 2024-10-02 04:01:12

感谢888

这看起来有点复杂,但它确实有效。

将字段转换为数组,然后再转换回字符串。

var foo = dc.foos.First();
string formula = new string(foo.Formula2.ToArray());

With thanks to 888.

This seems a little convoluted but it worked.

Convert the field to an array, then back to a string.

var foo = dc.foos.First();
string formula = new string(foo.Formula2.ToArray());
写给空气的情书 2024-10-02 04:01:12

听起来像 .net 将 varchar 转换为 nvarchar
我不知道如何直接解决它。但 System.Text.Encoding 可能有帮助
试试这个

//1 set col in db to varbinary(max)

//2 and when u want to save to db
string formula = "...";
System.Data.Linq.Binary bin = new System.Data.Linq.Binary(System.Text.Encoding.ASCII.GetBytes());

//3 when u pull ou
    Binary bin = row.Formula2;
    string formula = System.Text.Encoding.ASCII.GetString(bin.ToArray());

sounds like .net convert varchar to nvarchar
i dont know how to directly solve it. but System.Text.Encoding might help
try this

//1 set col in db to varbinary(max)

//2 and when u want to save to db
string formula = "...";
System.Data.Linq.Binary bin = new System.Data.Linq.Binary(System.Text.Encoding.ASCII.GetBytes());

//3 when u pull ou
    Binary bin = row.Formula2;
    string formula = System.Text.Encoding.ASCII.GetString(bin.ToArray());
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文