【发布时间】:2014-11-10 16:17:08
【问题描述】:
当尝试从模型对我的数据库上下文执行 .Where() 时,我收到以下错误消息:
System.Data.Entity<RPSManagementSystem.Model.StoreUser> does not contain a definition for Where...
这在从控制器调用时有效。什么给了?
来自模型:
[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;
}
}
为了确保我没有发疯,我将它粘贴到我的控制器中 - 它看起来可以正常工作。截图如下:
在模型中:
在控制器中:
【问题讨论】:
-
你添加
using System.Linq;了吗? -
@Alberto facepalm 你成功了。您可以将此作为答案发布,以便我将其标记为已接受吗?
标签: c# asp.net entity-framework