In EF 4.1, how can I foreach through my dbcontext entities?

asp.net-mvc-3 dbcontext entity-framework objectcontext objectstatemanager

Question

ASP.NET Entity Framework 4.1 MVC 3 (C#) is what I'm using.

In my DbContext, I want to foreach through each entity. To create dynamic views, I need to be able to dynamically refer to my entities.

I've read Lerman's book, two books on MVC (2 & 3), asp.net, msdn, etc. Perhaps I'm simply overlooking something?

It seems that in order to access the entities, you may need to utilize ObjectContext. If it is the proper method, I'm not sure how to go about doing it. Thank you. I'm grateful.

1
4
6/13/2011 3:38:12 PM

Popular Answer

Additionally, you might (for instance):

foreach (var dbItem in dbContext.Items)
{
    //do what you want inside the loop with the dbItem
    sList.Add(new SelectListItem() {Text = dbItem.ItemName, Value = dbItem.ItemTag});
}
3
10/16/2011 10:12:53 PM


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