From a9ad62a4c36f5e745d4a4fdd067f0c7a0ccc7818 Mon Sep 17 00:00:00 2001 From: game4353 <73753515+game4353@users.noreply.github.com> Date: Wed, 29 May 2024 20:23:22 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A0=EF=B8=8FProtocol.Echelon=5FSave?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Api/ProtocolHandlers/Echelon.cs | 8 ++++++-- SCHALE.GameServer/Services/AutoMapper.cs | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/SCHALE.GameServer/Controllers/Api/ProtocolHandlers/Echelon.cs b/SCHALE.GameServer/Controllers/Api/ProtocolHandlers/Echelon.cs index 8357395..ec6b436 100644 --- a/SCHALE.GameServer/Controllers/Api/ProtocolHandlers/Echelon.cs +++ b/SCHALE.GameServer/Controllers/Api/ProtocolHandlers/Echelon.cs @@ -1,4 +1,5 @@ using AutoMapper; +using Microsoft.EntityFrameworkCore; using SCHALE.Common.Database; using SCHALE.Common.Database.ModelExtensions; using SCHALE.Common.FlatData; @@ -12,13 +13,14 @@ namespace SCHALE.GameServer.Controllers.Api.ProtocolHandlers ISessionKeyService _sessionKeyService, SCHALEContext _context, ExcelTableService _excelTableService, + ILogger _logger, IMapper _mapper ) : ProtocolHandlerBase(protocolHandlerFactory) { private readonly ISessionKeyService sessionKeyService = _sessionKeyService; private readonly SCHALEContext context = _context; private readonly ExcelTableService excelTableService = _excelTableService; - + private readonly ILogger logger = _logger; private readonly IMapper mapper = _mapper; [ProtocolHandler(Protocol.Echelon_List)] @@ -43,8 +45,10 @@ namespace SCHALE.GameServer.Controllers.Api.ProtocolHandlers context.Echelons.Add(db); else { - db.ServerId = old.ServerId; + // https://github.com/dotnet/efcore/issues/9156 + context.Entry(old).State = EntityState.Detached; mapper.Map(db, old); + context.Entry(old).State = EntityState.Modified; } context.SaveChanges(); return new EchelonSaveResponse() { EchelonDB = db, }; diff --git a/SCHALE.GameServer/Services/AutoMapper.cs b/SCHALE.GameServer/Services/AutoMapper.cs index 48b2675..e040326 100644 --- a/SCHALE.GameServer/Services/AutoMapper.cs +++ b/SCHALE.GameServer/Services/AutoMapper.cs @@ -7,7 +7,7 @@ namespace SCHALE.GameServer.Services { public MappingProfile() { - CreateMap(); + CreateMap().ForMember(x => x.ServerId, opt => opt.Ignore()); } } }