序列不包含任何元素? [英] Sequence contains no elements?

查看:199
本文介绍了序列不包含任何元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用在两个地方一个查询来获取从数据库中的行。

I'm currently using a single query in two places to get a row from a database.

BlogPost post = (from p in dc.BlogPosts
                 where p.BlogPostID == ID
                 select p).Single();

查询检索行数据放在文本框的时候是好的,但它返回一个错误序列不包含任何元素用于检索该行以编辑它,把它放回到数据库时。我不明白为什么它可能在一个实例中找到一个合适的行,但不是其他。

The query is fine when retrieving the row to put data in to the text boxes, but it returns an error "Sequence contains no elements" when used to retrieve the row in order to edit it and put it back in to the database. I can't understand why it might find an appropriate row in one instance but not another.

(使用ASP.NET MVC和LINQ)

(Using ASP.NET MVC and LINQ)

推荐答案

放在该行断点,或者收到了Debug.Print,在这两种情况下,看看什么ID包含的内容。

Put a breakpoint on that line, or a Debug.Print before it, in both cases and see what ID contains.

这篇关于序列不包含任何元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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