fix account items not updated

This commit is contained in:
mkbka 2024-06-03 20:11:58 +08:00
parent b20b695f11
commit 11c035d083
3 changed files with 25 additions and 2 deletions

View File

@ -4,6 +4,7 @@ using SCHALE.Common.Database.ModelExtensions;
using SCHALE.Common.NetworkProtocol; using SCHALE.Common.NetworkProtocol;
using SCHALE.Common.Utils; using SCHALE.Common.Utils;
using SCHALE.GameServer.Services; using SCHALE.GameServer.Services;
using SCHALE.GameServer.Utils;
namespace SCHALE.GameServer.Controllers.Api.ProtocolHandlers namespace SCHALE.GameServer.Controllers.Api.ProtocolHandlers
{ {
@ -280,6 +281,8 @@ namespace SCHALE.GameServer.Controllers.Api.ProtocolHandlers
_context.SaveChanges(); _context.SaveChanges();
transaction.Commit(); transaction.Commit();
_context.Entry(account).Collection(x => x.Items).Reload();
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -1,5 +1,5 @@
using SCHALE.Common.Extensions; using SCHALE.Common.FlatData;
using SCHALE.Common.FlatData; using SCHALE.Common.Utils;
namespace SCHALE.GameServer.Services namespace SCHALE.GameServer.Services
{ {

View File

@ -0,0 +1,20 @@
using Microsoft.EntityFrameworkCore.ChangeTracking;
namespace SCHALE.GameServer.Utils;
public static class CollectionEntryExt
{
public static void Reload(this CollectionEntry source)
{
if (source.CurrentValue != null)
{
foreach (var item in source.CurrentValue)
{
source.EntityEntry.Context.Entry(item).State = Microsoft.EntityFrameworkCore.EntityState.Detached;
}
source.CurrentValue = null;
source.IsLoaded = false;
source.Load();
}
}
}