使用 Linq to SQL 从存储过程返回空值
如果我在数据库 (SQL 2000) 中运行存储过程并返回 SCOPE_IDENTITY,我会收到一个值。但是,使用 LINQ to SQL,我得到 Column1 属性的空值。有人有建议吗?
If I run a stored procedure in my database (SQL 2000) and return the SCOPE_IDENTITY, I receive a value. However, using LINQ to SQL, I get a null value for the Column1 property. Anyone have a suggestion?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保 SP 末尾只有一条 SELECT 语句。所以,像这样:
另外,重命名 select 语句中的列,并可能将其转换为正确的数据类型。像这样的事情:
一周前我遇到了这个问题,因为我在 SP 中有 2 个 SELECT 语句,并且它们互相搞砸了。 SP 总是做它应该做的事情,但它总是返回 null。自从我改用上面写的内容以来,它就像一个魅力。
希望这对您有帮助
Make sure you have only one SELECT statement at the end of your SP. So, something like this:
Also, rename your column in the select statement and possibly cast it into proper data type. Something like this:
I ran into this a week ago because I had 2 SELECT statements in a SP and they were screwing each other up. The SP always did what it was supposed to but it always sent null back. Since I switched to what I wrote above it's worked like a charm.
Hope this helps you