I have the following method in my code;
Invoice GetInvoice()
{
return entities.Invoices.First(i => i.InvoiceNo == invoiceData.InvoiceId);
}
I have read about first level caching but I'm not sure what happens inside EF6 if I do something like this;
Scenario 1: Get the invoice and hold a local reference;
var invoice = GetInvoice();
invoice.UpdatedBy = "Pete"
invoice.UpdatedTime = DateTime.Now;
Scenario 2: Call GetInvoice every time I want to update the invoice;
GetInvoice().UpdatedBy = "Pete"
GetInvoice().UpdatedTime = DateTime.Now;
In the second scenario does the entity framework query the database a second time or does it just return a cached instance of the invoice (checking for cached instances first and only querying the database if it finds none)?