Uncategorized

How to update the Entity Framework model, when changing stored procedure in Database

Solution:

All you need to do is to open your entity model diagram window, then click on Model Browser then go through each and delete the desired stored procedure artifacts in below folders and SAVE the file.

  1. Complex Types
  2. Function Imports
  3. Stored Procedures / Functions

Development, Entity Framework, Uncategorized

How to force Entity Framework to Always Load Fresh copy of Data from the Database

How to force Entity Framework to Always Load Fresh copy of Data from the Database

Solution:

There are many solution to achieve this result.

The most popular and easiest one is to dispose the existing context object and create new one

entities.Dispose();
entities = new Entities(); // DbContext

but it is not optimal you are disposing whole context which could be very expensive.

Optimal Solution:

Db.Entry(item).Reload(); // Db here means DbContext

this will only load the entity (item) you passed from the database and if you changed the item before reload, after reload the change will be overwritten by the values coming from database.

For more information Please check

Development, Entity Framework, Uncategorized

How to force Entity Framework to Always Load Fresh copy of Data from the Database

How to force Entity Framework to Always Load Fresh copy of Data from the Database

Solution:

There are many solution to achieve this result.

The most popular and easiest one is to dispose the existing context object and create new one

entities.Dispose();
entities = new Entities(); // DbContext

but it is not optimal you are disposing whole context which could be very expensive.

Optimal Solution:

Db.Entry(item).Reload(); // Db here means DbContext

this will only load the entity (item) you passed from the database and if you changed the item before reload, after reload the change will be overwritten by the values coming from database.

For more information Please check