Reputation: 295
I'm using a scaffold-ed index function to get all the data from the database.
// Scaffold-ed index():
public ActionResult Index()
{
return View(db.Objects.ToList());
}
// Database tables:
[ObjectID] [Name]
1 Tree
2 Plant
3 Flower
4 Tree
Instead of all the objects, I only what the objects with a certain name (for example: tree). What is the best solution for this and should this be done with methods like db.Objects.Find()
, Where()
,.. or with a custom query?
Upvotes: 0
Views: 277
Reputation: 1187
Linq is good for this the code needed would be
db.Objects.Where(o => o.Name == "Tree").ToList();
Upvotes: 2