I'm creating a communication app (using .net core 1.1 mvc and signalr/knockout ) and I have the following pocos:
room user post postRevision
posts is a container of postRevision, which for convenience has a reference to the latest revision
everything else is as you would imagine it. I'm omitting a lot of details obviously.
My user has an avatar property. When I update the user's avatar I delete their old avatar, and update to the new one. Then in the room the posts (postRevisions really) by said user no-longer have a friendly avatar, now they have a broken image icon. I'm still developing, so this is not happening in a multi-user scenario. This is just me jumping from the mvc controller that changes avatars to the signalr/knockout page that displays posts.
When I stop and run the server the images are fixed. It looks like entity framework is caching the results and not updating.
in my controller I have this code snippet:
user.Avatar = imageId.ToString();
_context.Entry(user).State = EntityState.Modified;
await _context.SaveChangesAsync();
_context.Entry(user).State = EntityState.Detached;
return new JsonResult(new { status = "sucess" });
in my hub I have this snippet for fetching a page of posts:
data = await _context.Posts
.Include(x=> x.LatestRevision)
.Include(x => x.LatestRevision.Blob)
.Include(x => x.LatestRevision.Creator)
.Where(x=> x.Room.Id == roomId
&& x.Id < currentPostId)
.OrderByDescending(x => x.Id)
.Take(_roomPageSize).ToListAsync();
I'm not sure how to tell the signalr context to update, especially since that page isn't open, and in theory that page is out of scope, so that context isn't even created yet. This is the relevant portion of my Startup.cs
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>();