C
C#13mo ago
Exi

✅ Blazorserver - Value after manual db-update not changing after new fetch

Hello, I setup a blazorserver project and implemented a db connection and wanted to load user data. Problem: My user table has a column called "IsActive" (bit). Now I fetch a record from a user where the IsActive = 0 and my response user property IsActive = false - so far so good. Now I manually update the IsActive value on the database to 1 and call the function again to fetch the new information. Using EF Core btw ... if I run the query which is sent to the sql data provider I get the correct result with isactive = 1, but if I log the response user, the property IsActive is still false. After I stop the program and restart it, the data gets fetched correctly. It feels like it get cached or smth, no idea why it wont update the value it gets from the query. Anyone can give me some hints or the solution to this? I've read smth about ChangeTracking and used AsNoTracking() but that didnt help. Code Parts:
readonly ApplicationContext _database;
public UserRepository(ApplicationContext database)
{
this._database = database;
}

var user = await _database.Users.FirstOrDefaultAsync(u => userId > 0 ? u.UserId == userId : u.Email == email);
Console.WriteLine($"Email: {user!.Email}, IsActive: {user.IsActive}");
readonly ApplicationContext _database;
public UserRepository(ApplicationContext database)
{
this._database = database;
}

var user = await _database.Users.FirstOrDefaultAsync(u => userId > 0 ? u.UserId == userId : u.Email == email);
Console.WriteLine($"Email: {user!.Email}, IsActive: {user.IsActive}");
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?