DBSet不包含Where [duplicate]的定义

时间:2021-12-25 16:57:04

This question already has an answer here:

这个问题已经有了答案:

When trying to execute a .Where() on my database context from a model, I am hit with this error message:

当我试图在我的数据库上下文中从一个模型执行.Where()时,我收到了以下错误消息:

System.Data.Entity<RPSManagementSystem.Model.StoreUser> does not contain a definition for Where...

This works when calling it from a controller. What gives?

这在从控制器调用它时是有效的。到底发生了什么事?

From the model:

从模型:

[NotMapped]
private List<StoreUser> _stores { get; set; }
[NotMapped]
public List<StoreUser> Stores
{
    get
    {
        if (this._stores == null || this._stores.Count <= 0)
        {
            using (RPSEntities db = new RPSEntities())
            {
                this._stores = db.StoreUsers.Where(su => su.Username == this.Username);
            }
        }

        return _stores;
    }
}    

Just to make sure I'm not crazy, I pasted this into my controller - where it looks to be working. Screenshots below:

为了确保我没有疯,我把它粘贴到我的控制器中——它看起来在工作。截图:

in the model:

在模型中:

DBSet不包含Where [duplicate]的定义

in the controller:

控制器:

DBSet不包含Where [duplicate]的定义

1 个解决方案

#1


49  

Add using System.Linq; in your model class

使用来增加;在你的模型类

#1


49  

Add using System.Linq; in your model class

使用来增加;在你的模型类