From b6c85b1c4b92ed31e891d8ec3f871d6bd05f2ac8 Mon Sep 17 00:00:00 2001 From: Sam <315859133@qq.com> Date: Fri, 6 Feb 2026 00:55:58 +0800 Subject: [PATCH] fix: configure TenantInfo as owned entity and use AsNoTracking - Add AsNoTracking to tenant query to avoid tracking conflicts - Configure TenantInfo as owned entity in ApplicationUser - Map TenantInfo properties to separate columns in AspNetUsers table --- Data/ApplicationDbContext.cs | 8 ++++++++ Data/SeedData.cs | 1 + Fengling.AuthService.csproj | 32 ++++++++++++++++---------------- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/Data/ApplicationDbContext.cs b/Data/ApplicationDbContext.cs index 39ebe18..23b0f93 100644 --- a/Data/ApplicationDbContext.cs +++ b/Data/ApplicationDbContext.cs @@ -25,6 +25,14 @@ public class ApplicationDbContext : IdentityDbContext e.RealName).HasMaxLength(100); entity.Property(e => e.Phone).HasMaxLength(20); entity.HasIndex(e => e.Phone).IsUnique(); + + entity.OwnsOne(e => e.TenantInfo, navigationBuilder => + { + navigationBuilder.Property(e => e.Id).HasColumnName("TenantId"); + navigationBuilder.Property(e => e.TenantId).HasColumnName("TenantCode"); + navigationBuilder.Property(e => e.Name).HasColumnName("TenantName"); + navigationBuilder.WithOwner(); + }); }); builder.Entity(entity => diff --git a/Data/SeedData.cs b/Data/SeedData.cs index 351aaba..ab2ca0c 100644 --- a/Data/SeedData.cs +++ b/Data/SeedData.cs @@ -16,6 +16,7 @@ public static class SeedData context.Database.EnsureCreated(); var defaultTenant = await context.Tenants + .AsNoTracking() .FirstOrDefaultAsync(t => t.TenantId == "default"); if (defaultTenant == null) { diff --git a/Fengling.AuthService.csproj b/Fengling.AuthService.csproj index 30dfedf..9fb5156 100644 --- a/Fengling.AuthService.csproj +++ b/Fengling.AuthService.csproj @@ -6,25 +6,25 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - - - - - - - + + + + + + + + + + + + + +