当前上下文中不存在名称 xxx。 我究竟做错了什么?
var result = from lr in _db.LeaveRequest
join th in _db.TotalHourslu
on lr.TotalHoursEffect
equals th.Minutesselect
select new { lr.TotalHoursEffect, th.Minutes, tr.Display };
错误: 当前上下文中不存在名称“_db” 当前上下文中不存在名称“_db” 当前上下文中不存在名称“tr”
var result = from lr in _db.LeaveRequest
join th in _db.TotalHourslu
on lr.TotalHoursEffect
equals th.Minutesselect
select new { lr.TotalHoursEffect, th.Minutes, tr.Display };
ERROR:
The name '_db' does not exist in the current context
The name '_db' does not exist in the current context
The name ' tr ' does not exist in the current context
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该错误意味着当前上下文中没有可访问的名为 _db 或 tr 的对象。 这意味着不存在具有这些名称的方法局部变量、类成员变量或全局变量。 您是否可能复制粘贴一些代码而忘记将变量重命名为正确的名称?
另请记住,一个类中的成员变量无法从其他类访问,除非您在它们前面加上“ClassName.”前缀,例如 NameOfClassWhereDBIsDefined._db。 如果 _db 是私有成员(可能就是这样),那么这甚至不起作用。 在这种情况下,您必须将 _db 作为参数传递给函数,或者通过 getter 方法/属性来访问它。
That error means there are no objects named _db or tr accessible in the current context. This means there are no method-local, class-member or global variables with those names. Did you possibly copy-paste some code and forgot to rename the variables to the correct names?
Also remember that member variables in one class are not accessible from other classes unless you prefix them with "ClassName.", like NameOfClassWhereDBIsDefined._db. And that won't even work if _db is a private member, like it probably is. In that case, you would have to pass _db in as a parameter to the function, or have it accessible through a getter method/property.
您是否忘记添加
到类中作为成员变量?
Did you forget to add
to your class as a member variable?