开发者

Entity Framework 4.0 won't let me use LINQ-to-Entities

开发者 https://www.devze.com 2023-02-14 16:24 出处:网络
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.

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


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消