Andreas
Andreas

Reputation: 116

Refresh Data in Entity Framework

When I open my program and try to get all my users the following code will be executed:

    public static List<User> GetAllUsers()
    {
        return db.Users.OrderBy(x => x.ID).ToList();
    }

If I go to my SQL Server Management Studio and change some value and redo GetAllUsers(); the data is still the same. Is there any way to refresh the data? Best would be to even refresh all (I have other classes in my DbContext) so i actually reload everything.

Upvotes: 0

Views: 165

Answers (1)

George Vovos
George Vovos

Reputation: 7618

Check this question How to Refresh DbContext

But i suggest not to use a static dbcontext,check this
Pros and Cons of putting a db context in static class library

Upvotes: 1

Related Questions