[英]Entity Framework First() does not return any records
I am having issues with entity framework. 我在实体框架方面遇到问题。 The following code does not return anything:
以下代码不返回任何内容:
Warehouse warehouse = dbcontext.Warehouses.First();
But if I add a break point and mouse over Warehouses I can browse records of the table, but First() doesn't return anything. 但是,如果添加断点并将鼠标悬停在Warehouse上,则可以浏览表的记录,但是First()不会返回任何内容。 In the Immediate Window if I try warehouse.Name I get the error "The name warehouse does not exist in the current context."
如果我尝试使用Warehouse.Name,则在“立即窗口”中将收到错误消息:“名称仓库在当前上下文中不存在。”
The table has around 10,000 records, could this be causing any issues? 该表有大约10,000条记录,这可能会引起任何问题吗?
edit: I have tried: 编辑:我尝试过:
int count = dbcontext.Warehouses.Count();
and the result was 0. This is after I was able to mouse over dbcontext.Warehouses and view records from the table. 结果为0。这是在我能够将鼠标悬停在dbcontext.Warehouses并从表中查看记录之后。 I removed the breakpoing then displayed the result on a webpage and it also displayed 0. So it isn't something I just saw while debugging.
我删除了Breakpoing,然后在网页上显示了结果,并且还显示了0。所以这不是我在调试时看到的东西。
If you are inspecting your variable just below the line where warehouse is declared, and you receive error that warehouse doesn't exist in the current context, it might happen that your debug info is not ok. 如果您在声明仓库的行的下方检查变量,并且收到错误消息,即当前上下文中不存在仓库,则可能发生调试信息不正确的情况。 Try to clean/rebuild your project and run Debug configuration.
尝试清理/重建项目并运行“调试”配置。 If you still receive the same error, then you are really out of scope of that variable when you try to inspect it's value.
如果仍然收到相同的错误,则当您尝试检查变量的值时,您实际上超出了该变量的范围。 After your edit: check your connection string, it might happen that you are pointing to a wrong database.
编辑后:检查连接字符串,可能是您指向错误的数据库。 Also, check out source for your entity classes, it might happen that Warehouses is not pointing to a table you think it points to.
另外,请检查您的实体类的源,这可能会导致Warehouses没有指向您认为它指向的表。 Also, have you tried dbcontext.Warehouses.Select(w=>w).First() ?
另外,您是否尝试过dbcontext.Warehouses.Select(w => w).First()?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.