I just got into Entity Framework 4 and, in the end, hoped to wrap it in a repository template using POCOs. I discovered something that I did not expect. It seems that if you create a context, add an object to it (without saving the context) and request the context again, it does not include the new object in the results. Am I doing something wrong? It seems that it should return what I added, even if I have not yet saved the results to the database. Here is my sample code:
ShopEntities context = new ShopEntities();
var customers = from c in context.Customers
select c;
Console.WriteLine(customers.Count());
Customer newCustomer = context.Customers.CreateObject();
newCustomer.FirstName = "Joe";
newCustomer.LastName = "Smith";
context.Customers.AddObject(newCustomer);
var customers2 = from c in context.Customers
select c;
Console.WriteLine(customers2.Count());
context.SaveChanges();
var customers3 = from c in context.Customers
select c;
Console.WriteLine(customers3.Count());
source
share