DBSet不包含Where的定义 [英] DBSet does not contain a definition for Where

查看:72
本文介绍了DBSet不包含Where的定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试从模型在数据库上下文中执行.Where()时,遇到以下错误消息:

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

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

当从控制器调用它时有效.有什么作用?

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

来自模型:

[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:

在模型中:

在控制器中:

推荐答案

在模型类中使用System.Linq; 添加

Add using System.Linq; in your model class

这篇关于DBSet不包含Where的定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆