Entity Framework 4.0 不允许我使用 LINQ-to-Entities

发布于 2024-10-20 11:18:15 字数 630 浏览 1 评论 0原文

也许我有点工作过度了...我迷失在一个使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

戈亓 2024-10-27 11:18:15

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) 确保 TicketIDint 并将其与另一个 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's IDisposable):

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 is int and compare it to another int as in the updated snippet above.

乞讨 2024-10-27 11:18:15

噢...

我感觉真的很蠢...我发现了我的错误!

不知何故,以下 using 语句丢失了:o(

using System.Linq

我想,我必须请假。

谢谢大家投入时间来帮助我!

DeepCore

Doh...

I'm feeling really dumb... I have found my mistake!

Somehow the following using statement went missing :o(

using System.Linq

I think, I have to ask for some vacation.

Thank you all for investing your time to help me!

DeepCore

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文