I am teaching myself about the entity framework using a tutorial found at http://msdn.microsoft.com/en-us/data/jj591506.
using (var db = new DatabaseEntities())
{
// Section 1
var section = new Section
{
SectionID = 1,
SectionLetter = "d"
};
db.Sections.Add(section);
db.SaveChanges();
// Section 2
var query = from b in db.Sections
orderby b.SectionLetter
select b;
foreach (var item in query)
{
this.Title = item.SectionLetter;
}
}
When I use section 1 and section 2 of the code above together they work well. However, when I run just Section 2 the title does not change which means it does not even return a single item and thus does not enter the foreach loop. I can't see why it would not enter the loop.
I realise there is probably an obvious answer to this question but I thought I should ask on stackoverflow rather than ask a colleague so others with the same question could find an answer.
I suspect there might be a clue in this question: System.Data.Entity not working as expected for MVC Entity Framework. Unfortunately I can't seem to work it out.