Entity Framework 4.0 不允许我使用 LINQ-to-Entities
也许我有点工作过度了...我迷失在一个使用 EF4 进行数据库处理的项目中。
因此,它确实可以很好地检索实体的完整列表。 但是当我尝试进行一些过滤时,我不明白...
我有以下代码,我遇到了大麻烦
public class InfoViewModel
{
private TrackerEntities _context;
public InfoViewModel (int ticketID)
{
var ct = new TrackerEntities();
var res = from t in ct.Tickets
where t.TicketID // VS2010 can't evaluate the property 'TicketID'
select t;
}
}
我不明白为什么 t.TicketID 会向我抛出带有错误消息的波浪红线 “无法解析符号‘TicketID’”
该符号是在 EDMX 文件中声明的,具有公共 getter 和 setter...
事实上,看起来在我的类中该实体一无所知。
为什么?
TIA 深核
Maybe I'm somewhat over-worked ... I'm lost in a project where I use EF4 for the DB stuff.
As such, it does work indeed well to retrieve a complete list of an entity.
But when I try to do some filtering, I don't get it...
I have the following code, where I get in big trouble
public class InfoViewModel
{
private TrackerEntities _context;
public InfoViewModel (int ticketID)
{
var ct = new TrackerEntities();
var res = from t in ct.Tickets
where t.TicketID // VS2010 can't evaluate the property 'TicketID'
select t;
}
}
I do not understand why t.TicketID throws me the wavy red line with the error message
"Can not resolve symbol 'TicketID'"
The symbol is declared in the EDMX file, with public getter and setter...
In fact, it looks like nothing of the entity is known in my class.
Why?
TIA
DeepCore
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
1) 您应该将实体的 TicketID 与所需的匹配项进行比较,并且(推荐)您应该将上下文实例包装在
using
语句(它是IDisposable
):private TrackerEntities _context;
public InfoViewModel(int TicketID)
{
var ct = new TrackerEntities();
var res = 来自 ct.Tickets 中的 t
其中
t.TicketID == TicketID
选择t;
}
2) 尝试刷新模型;转到 EDM 设计器,右键单击曲面并选择“从数据库更新模型”,可能架构中有错误。
3) 确保
TicketID
属性与 EDM 中的拼写和大小写相同。4) 确保
TicketID
为int
并将其与另一个 int 进行比较,如上面更新的代码片段所示。1) you should compare the TicketID of the entity with the desired match, and (recommended) you should wrap the context instance in a
using
statement (it'sIDisposable
):private TrackerEntities _context;
public InfoViewModel(int ticketID)
{
var ct = new TrackerEntities();
var res = from t in ct.Tickets
where
t.TicketID == ticketID
select t;
}
2) Try refreshing the model; go to the EDM designer, right click the surface and select "Update Model from Database", maybe there is an error in the schema.
3) Make sure the
TicketID
property is the same spelling and casing as in the EDM.4) Make sure the
TicketID
isint
and compare it to another int as in the updated snippet above.噢...
我感觉真的很蠢...我发现了我的错误!
不知何故,以下 using 语句丢失了:o(
我想,我必须请假。
谢谢大家投入时间来帮助我!
DeepCore
Doh...
I'm feeling really dumb... I have found my mistake!
Somehow the following using statement went missing :o(
I think, I have to ask for some vacation.
Thank you all for investing your time to help me!
DeepCore