LINQ to SQL 中数据库中存在空字符串的错误

发布于 2024-12-10 21:17:27 字数 391 浏览 7 评论 0原文

我已经使用 LINQ to SQL 多年了,但这是我第一次看到这种行为。

我有一个数据库表,其中有几列 (varchar(15)),其中可能包含空字符串 ('')。我通过运行 LEN(Column) 并检查结果为 0 来验证这一点。

现在,当我从 LINQ2SQL 调用它时,它返回对象字段,其中包含一个包含单个空格的字符串 (string.Length == 1)。

我可以应用一些解决方法,例如在数据库上将它们设为 NULL 或修剪字符串,但我想知道之前是否有人遇到过这种情况,或者该错误是否已知(报告于微软连接)。如果没有,我会报告。

谢谢。

I have been using LINQ to SQL for years now, but this is the first time I have seen this behavior.

I have a DB table with a few columns (varchar(15)) that may contain empty strings (''). I verify this by running LEN(Column) and checking the result be 0.

Now when I call this from LINQ2SQL, it returns the object field with a string containing a single space (string.Length == 1).

There are a few workarounds I could apply, like making them NULL on the DB or trimming the string, but I would like to know if anyone has come across this before or if the bug is known (reported on MS Connect). If not, I'll report it.

Thanks.

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

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

发布评论

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

评论(1

╄→承喏 2024-12-17 21:17:27

问题出在 LEN 函数上:

SELECT LEN(' ')

在 SQL Server 中返回 0;这是一个完整的 PITA。

SELECT DATALENGTH(' ')

返回 1

The issue is with the LEN function:

SELECT LEN(' ')

Returns 0 in SQL Server; it is a total PITA.

But

SELECT DATALENGTH(' ')

Returns 1

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文