DBSet does not contain a definition for Where

asp.net c# entity-framework

Question

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?

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:

enter image description here

in the controller:

enter image description here

1
20
11/10/2014 4:17:08 PM

Accepted Answer

Add using System.Linq; in your model class

77
11/11/2014 8:27:31 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow