user3231419
user3231419

Reputation: 295

ASP.NET MVC Retrieve data with certain name

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

Answers (1)

Rajdeep Dosanjh
Rajdeep Dosanjh

Reputation: 1187

Linq is good for this the code needed would be

db.Objects.Where(o => o.Name == "Tree").ToList();

Upvotes: 2

Related Questions