I am developing an Asp.Net mvc project using Entity Framework code first approach. But I am trying to improve performance of my application. I am not clear that Entity Framework run database query again or not if I access the same condition again.
Here is my code:
var item = context.Items.FirstOrDefault();// Database query will be run for this
var start = item.Promotions.FirstOrDefault().Start; // Another query will be run for this
var end = item.Promotions.FirstOrDefault().End; //Will another query be run again? Same query is run again for this
var price = item.Promotions.FirstOrDefault().Price; //Here also
As you can see in the code, new query will be run to retrieve promotion start date. But when I retrieve end date, database will run the query again even if they are same query. I am confused by it.