From 78ea8fd9ed79db9fd6f97dd77ca2f31da88f4722 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=AD=E6=98=8E=E9=94=8B?= Date: Fri, 19 Mar 2021 21:06:27 +0800 Subject: [PATCH] =?UTF-8?q?feat(efcore):=20=E6=9B=B4=E6=96=B0=E5=8F=97=20#?= =?UTF-8?q?215=20=E6=9B=B4=E6=94=B9=E5=BD=B1=E5=93=8D=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/IdentityController.cs | 24 +- .../Hangfire/HangfireJobRunner.cs | 6 +- .../Hangfire/HangfireJobRunner.cs | 6 +- .../20201116154409_Init.Designer.cs | 1130 ----------------- .../Migrations/20210305130944_Menu.cs | 51 - ...ner.cs => 20210318164423_Init.Designer.cs} | 6 +- ...6154409_Init.cs => 20210318164423_Init.cs} | 452 ++++--- .../DefaultDbContextModelSnapshot.cs | 2 +- .../Mvc/Filters/AuditOperationAttribute.cs | 11 +- .../Mvc/Filters/UnitOfWorkAttribute.cs | 109 +- .../Mvc/Filters/UnitOfWorkFilterImpl.cs | 132 -- src/OSharp.AspNetCore/Mvc/MvcPackBase.cs | 3 +- .../ModuleHandlerBase.cs | 5 +- .../DbContextExtensions.cs | 13 + .../EntityFrameworkCorePackBase.cs | 2 +- src/OSharp.EntityFrameworkCore/Repository.cs | 9 +- .../RepositoryExtensions.cs | 3 +- .../SqlExecutorBase.cs | 3 +- .../TableNamePrefixConfiguration.cs | 3 +- .../Controllers/IdentityController.cs | 14 +- .../JwtBearer/JwtBearerService.cs | 24 +- .../Identity/OnlineUserProvider.cs | 2 +- .../EntityInfos/EntityInfoHandlerBase.cs | 4 +- .../Functions/FunctionHandlerBase.cs | 4 +- .../DynamicProxy/TransactionalAttribute.cs | 14 +- src/OSharp/Entity/IRepository.cs | 4 +- src/OSharp/Extensions/ServiceExtensions.cs | 44 +- 27 files changed, 464 insertions(+), 1616 deletions(-) delete mode 100644 samples/web/Liuliu.Demo.WebApi/Migrations/20201116154409_Init.Designer.cs delete mode 100644 samples/web/Liuliu.Demo.WebApi/Migrations/20210305130944_Menu.cs rename samples/web/Liuliu.Demo.WebApi/Migrations/{20210305130944_Menu.Designer.cs => 20210318164423_Init.Designer.cs} (99%) rename samples/web/Liuliu.Demo.WebApi/Migrations/{20201116154409_Init.cs => 20210318164423_Init.cs} (62%) delete mode 100644 src/OSharp.AspNetCore/Mvc/Filters/UnitOfWorkFilterImpl.cs diff --git a/samples/web/Liuliu.Demo.Web/Controllers/IdentityController.cs b/samples/web/Liuliu.Demo.Web/Controllers/IdentityController.cs index 4f39464ea..a3936ba50 100644 --- a/samples/web/Liuliu.Demo.Web/Controllers/IdentityController.cs +++ b/samples/web/Liuliu.Demo.Web/Controllers/IdentityController.cs @@ -181,12 +181,12 @@ public async Task Login(LoginDto dto) dto.Ip = HttpContext.GetClientIp(); dto.UserAgent = Request.Headers["User-Agent"].FirstOrDefault(); + IUnitOfWork unitOfWork = HttpContext.RequestServices.GetUnitOfWork(true); OperationResult result = await _identityContract.Login(dto); - IUnitOfWorkManager unitOfWorkManager = HttpContext.RequestServices.GetRequiredService(); #if NET5_0 - await unitOfWorkManager.CommitAsync(); + await unitOfWork.CommitAsync(); #else - unitOfWorkManager.Commit(); + unitOfWork.Commit(); #endif if (!result.Succeeded) @@ -223,12 +223,12 @@ public async Task Token(TokenDto dto) UserAgent = Request.Headers["User-Agent"].FirstOrDefault() }; + IUnitOfWork unitOfWork = HttpContext.RequestServices.GetUnitOfWork(true); OperationResult result = await _identityContract.Login(loginDto); - IUnitOfWorkManager unitOfWorkManager = HttpContext.RequestServices.GetRequiredService(); #if NET5_0 - await unitOfWorkManager.CommitAsync(); + await unitOfWork.CommitAsync(); #else - unitOfWorkManager.Commit(); + unitOfWork.Commit(); #endif if (!result.Succeeded) { @@ -338,12 +338,12 @@ public PageData ReadOAuth2([FromServices] IFilterService fil public async Task LoginBind(UserLoginInfoEx loginInfo) { loginInfo.RegisterIp = HttpContext.GetClientIp(); + IUnitOfWork unitOfWork = HttpContext.RequestServices.GetUnitOfWork(true); OperationResult result = await _identityContract.LoginBind(loginInfo); - IUnitOfWorkManager unitOfWorkManager = HttpContext.RequestServices.GetRequiredService(); #if NET5_0 - await unitOfWorkManager.CommitAsync(); + await unitOfWork.CommitAsync(); #else - unitOfWorkManager.Commit(); + unitOfWork.Commit(); #endif if (!result.Succeeded) { @@ -364,12 +364,12 @@ public async Task LoginBind(UserLoginInfoEx loginInfo) public async Task LoginOneKey(UserLoginInfoEx loginInfo) { loginInfo.RegisterIp = HttpContext.GetClientIp(); + IUnitOfWork unitOfWork = HttpContext.RequestServices.GetUnitOfWork(true); OperationResult result = await _identityContract.LoginOneKey(loginInfo.ProviderKey); - IUnitOfWorkManager unitOfWorkManager = HttpContext.RequestServices.GetRequiredService(); #if NET5_0 - await unitOfWorkManager.CommitAsync(); + await unitOfWork.CommitAsync(); #else - unitOfWorkManager.Commit(); + unitOfWork.Commit(); #endif if (!result.Succeeded) diff --git a/samples/web/Liuliu.Demo.Web/Hangfire/HangfireJobRunner.cs b/samples/web/Liuliu.Demo.Web/Hangfire/HangfireJobRunner.cs index bb11f7ef0..0ae31a70b 100644 --- a/samples/web/Liuliu.Demo.Web/Hangfire/HangfireJobRunner.cs +++ b/samples/web/Liuliu.Demo.Web/Hangfire/HangfireJobRunner.cs @@ -74,12 +74,12 @@ public async Task LockUser2() User user2 = await userManager.FindByIdAsync("2"); list.Add($"user2.IsLocked: {user2.IsLocked}"); user2.IsLocked = !user2.IsLocked; + IUnitOfWork unitOfWork = _provider.GetUnitOfWork(true); await userManager.UpdateAsync(user2); - IUnitOfWorkManager unitOfWorkManager = _provider.GetService(); #if NET5_0 - await unitOfWorkManager.CommitAsync(); + await unitOfWork.CommitAsync(); #else - unitOfWorkManager.Commit(); + unitOfWork.Commit(); #endif user2 = await userManager.FindByIdAsync("2"); list.Add($"user2.IsLocked: {user2.IsLocked}"); diff --git a/samples/web/Liuliu.Demo.WebApi/Hangfire/HangfireJobRunner.cs b/samples/web/Liuliu.Demo.WebApi/Hangfire/HangfireJobRunner.cs index 04f50edec..736357de6 100644 --- a/samples/web/Liuliu.Demo.WebApi/Hangfire/HangfireJobRunner.cs +++ b/samples/web/Liuliu.Demo.WebApi/Hangfire/HangfireJobRunner.cs @@ -74,11 +74,11 @@ public async Task LockUser2() list.Add($"user2.IsLocked: {user2.IsLocked}"); user2.IsLocked = !user2.IsLocked; await userManager.UpdateAsync(user2); - IUnitOfWorkManager unitOfWorkManager = _provider.GetService(); + IUnitOfWork unitOfWork = _provider.GetUnitOfWork(true); #if NET5_0 - await unitOfWorkManager.CommitAsync(); + await unitOfWork.CommitAsync(); #else - unitOfWorkManager.Commit(); + unitOfWork.Commit(); #endif user2 = await userManager.FindByIdAsync("2"); list.Add($"user2.IsLocked: {user2.IsLocked}"); diff --git a/samples/web/Liuliu.Demo.WebApi/Migrations/20201116154409_Init.Designer.cs b/samples/web/Liuliu.Demo.WebApi/Migrations/20201116154409_Init.Designer.cs deleted file mode 100644 index 17d16b32a..000000000 --- a/samples/web/Liuliu.Demo.WebApi/Migrations/20201116154409_Init.Designer.cs +++ /dev/null @@ -1,1130 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using OSharp.Entity; - -namespace Liuliu.Demo.Web.Migrations -{ - [DbContext(typeof(DefaultDbContext))] - [Migration("20201116154409_Init")] - partial class Init - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "3.1.10"); - - modelBuilder.Entity("OSharp.Authorization.EntityInfos.EntityInfo", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("TEXT"); - - b.Property("AuditEnabled") - .HasColumnType("INTEGER"); - - b.Property("Name") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("PropertyJson") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("TypeName") - .IsRequired() - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.HasIndex("TypeName") - .IsUnique() - .HasName("ClassFullNameIndex"); - - b.ToTable("Auth_EntityInfo"); - }); - - modelBuilder.Entity("OSharp.Authorization.Functions.Function", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("TEXT"); - - b.Property("AccessType") - .HasColumnType("INTEGER"); - - b.Property("Action") - .HasColumnType("TEXT"); - - b.Property("Area") - .HasColumnType("TEXT"); - - b.Property("AuditEntityEnabled") - .HasColumnType("INTEGER"); - - b.Property("AuditOperationEnabled") - .HasColumnType("INTEGER"); - - b.Property("CacheExpirationSeconds") - .HasColumnType("INTEGER"); - - b.Property("Controller") - .HasColumnType("TEXT"); - - b.Property("IsAccessTypeChanged") - .HasColumnType("INTEGER"); - - b.Property("IsAjax") - .HasColumnType("INTEGER"); - - b.Property("IsCacheSliding") - .HasColumnType("INTEGER"); - - b.Property("IsController") - .HasColumnType("INTEGER"); - - b.Property("IsLocked") - .HasColumnType("INTEGER"); - - b.Property("Name") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.HasIndex("Area", "Controller", "Action") - .IsUnique() - .HasName("AreaControllerActionIndex"); - - b.ToTable("Auth_Function"); - }); - - modelBuilder.Entity("OSharp.Core.Systems.KeyValue", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("TEXT"); - - b.Property("IsLocked") - .HasColumnType("INTEGER"); - - b.Property("Key") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("ValueJson") - .HasColumnType("TEXT"); - - b.Property("ValueType") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.ToTable("Systems_KeyValue"); - }); - - modelBuilder.Entity("OSharp.Hosting.Authorization.Entities.EntityRole", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("TEXT"); - - b.Property("CreatedTime") - .HasColumnType("TEXT"); - - b.Property("EntityId") - .HasColumnType("TEXT"); - - b.Property("FilterGroupJson") - .HasColumnType("TEXT"); - - b.Property("IsLocked") - .HasColumnType("INTEGER"); - - b.Property("Operation") - .HasColumnType("INTEGER"); - - b.Property("RoleId") - .HasColumnType("INTEGER"); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.HasIndex("EntityId", "RoleId", "Operation") - .IsUnique() - .HasName("EntityRoleIndex"); - - b.ToTable("Auth_EntityRole"); - }); - - modelBuilder.Entity("OSharp.Hosting.Authorization.Entities.EntityUser", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("TEXT"); - - b.Property("CreatedTime") - .HasColumnType("TEXT"); - - b.Property("EntityId") - .HasColumnType("TEXT"); - - b.Property("FilterGroupJson") - .HasColumnType("TEXT"); - - b.Property("IsLocked") - .HasColumnType("INTEGER"); - - b.Property("UserId") - .HasColumnType("INTEGER"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.HasIndex("EntityId", "UserId") - .HasName("EntityUserIndex"); - - b.ToTable("Auth_EntityUser"); - }); - - modelBuilder.Entity("OSharp.Hosting.Authorization.Entities.Module", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("Code") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("Name") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("OrderCode") - .HasColumnType("REAL"); - - b.Property("ParentId") - .HasColumnType("INTEGER"); - - b.Property("Remark") - .HasColumnType("TEXT"); - - b.Property("TreePathString") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.HasIndex("ParentId"); - - b.ToTable("Auth_Module"); - }); - - modelBuilder.Entity("OSharp.Hosting.Authorization.Entities.ModuleFunction", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("TEXT"); - - b.Property("FunctionId") - .HasColumnType("TEXT"); - - b.Property("ModuleId") - .HasColumnType("INTEGER"); - - b.HasKey("Id"); - - b.HasIndex("FunctionId"); - - b.HasIndex("ModuleId", "FunctionId") - .IsUnique() - .HasName("ModuleFunctionIndex"); - - b.ToTable("Auth_ModuleFunction"); - }); - - modelBuilder.Entity("OSharp.Hosting.Authorization.Entities.ModuleRole", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("TEXT"); - - b.Property("ModuleId") - .HasColumnType("INTEGER"); - - b.Property("RoleId") - .HasColumnType("INTEGER"); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.HasIndex("ModuleId", "RoleId") - .IsUnique() - .HasName("ModuleRoleIndex"); - - b.ToTable("Auth_ModuleRole"); - }); - - modelBuilder.Entity("OSharp.Hosting.Authorization.Entities.ModuleUser", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("TEXT"); - - b.Property("Disabled") - .HasColumnType("INTEGER"); - - b.Property("ModuleId") - .HasColumnType("INTEGER"); - - b.Property("UserId") - .HasColumnType("INTEGER"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.HasIndex("ModuleId", "UserId") - .IsUnique() - .HasName("ModuleUserIndex"); - - b.ToTable("Auth_ModuleUser"); - }); - - modelBuilder.Entity("OSharp.Hosting.Identity.Entities.LoginLog", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("TEXT"); - - b.Property("CreatedTime") - .HasColumnType("TEXT"); - - b.Property("Ip") - .HasColumnType("TEXT"); - - b.Property("LogoutTime") - .HasColumnType("TEXT"); - - b.Property("UserAgent") - .HasColumnType("TEXT"); - - b.Property("UserId") - .HasColumnType("INTEGER"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("Identity_LoginLog"); - }); - - modelBuilder.Entity("OSharp.Hosting.Identity.Entities.Organization", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("Name") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("ParentId") - .HasColumnType("INTEGER"); - - b.Property("Remark") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.HasIndex("ParentId"); - - b.ToTable("Identity_Organization"); - }); - - modelBuilder.Entity("OSharp.Hosting.Identity.Entities.Role", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("TEXT"); - - b.Property("CreatedTime") - .HasColumnType("TEXT"); - - b.Property("DeletedTime") - .HasColumnType("TEXT"); - - b.Property("IsAdmin") - .HasColumnType("INTEGER"); - - b.Property("IsDefault") - .HasColumnType("INTEGER"); - - b.Property("IsLocked") - .HasColumnType("INTEGER"); - - b.Property("IsSystem") - .HasColumnType("INTEGER"); - - b.Property("MessageId") - .HasColumnType("TEXT"); - - b.Property("Name") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("NormalizedName") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("Remark") - .HasColumnType("TEXT") - .HasMaxLength(512); - - b.HasKey("Id"); - - b.HasIndex("MessageId"); - - b.HasIndex("NormalizedName", "DeletedTime") - .IsUnique() - .HasName("RoleNameIndex"); - - b.ToTable("Identity_Role"); - }); - - modelBuilder.Entity("OSharp.Hosting.Identity.Entities.RoleClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("ClaimType") - .HasColumnType("TEXT"); - - b.Property("ClaimValue") - .HasColumnType("TEXT"); - - b.Property("RoleId") - .HasColumnType("INTEGER"); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.ToTable("Identity_RoleClaim"); - }); - - modelBuilder.Entity("OSharp.Hosting.Identity.Entities.User", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("AccessFailedCount") - .HasColumnType("INTEGER"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("TEXT"); - - b.Property("CreatedTime") - .HasColumnType("TEXT"); - - b.Property("DeletedTime") - .HasColumnType("TEXT"); - - b.Property("Email") - .HasColumnType("TEXT"); - - b.Property("EmailConfirmed") - .HasColumnType("INTEGER"); - - b.Property("HeadImg") - .HasColumnType("TEXT"); - - b.Property("IsLocked") - .HasColumnType("INTEGER"); - - b.Property("IsSystem") - .HasColumnType("INTEGER"); - - b.Property("LockoutEnabled") - .HasColumnType("INTEGER"); - - b.Property("LockoutEnd") - .HasColumnType("TEXT"); - - b.Property("MessageId") - .HasColumnType("TEXT"); - - b.Property("NickName") - .HasColumnType("TEXT"); - - b.Property("NormalizeEmail") - .HasColumnType("TEXT"); - - b.Property("NormalizedUserName") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("PasswordHash") - .HasColumnType("TEXT"); - - b.Property("PhoneNumber") - .HasColumnType("TEXT"); - - b.Property("PhoneNumberConfirmed") - .HasColumnType("INTEGER"); - - b.Property("Remark") - .HasColumnType("TEXT"); - - b.Property("SecurityStamp") - .HasColumnType("TEXT"); - - b.Property("TwoFactorEnabled") - .HasColumnType("INTEGER"); - - b.Property("UserName") - .IsRequired() - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.HasIndex("MessageId"); - - b.HasIndex("NormalizeEmail", "DeletedTime") - .HasName("EmailIndex"); - - b.HasIndex("NormalizedUserName", "DeletedTime") - .IsUnique() - .HasName("UserNameIndex"); - - b.ToTable("Identity_User"); - }); - - modelBuilder.Entity("OSharp.Hosting.Identity.Entities.UserClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("ClaimType") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("ClaimValue") - .HasColumnType("TEXT"); - - b.Property("UserId") - .HasColumnType("INTEGER"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("Identity_UserClaim"); - }); - - modelBuilder.Entity("OSharp.Hosting.Identity.Entities.UserDetail", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("RegisterIp") - .HasColumnType("TEXT"); - - b.Property("UserId") - .HasColumnType("INTEGER"); - - b.HasKey("Id"); - - b.HasIndex("UserId") - .IsUnique(); - - b.ToTable("Identity_UserDetail"); - }); - - modelBuilder.Entity("OSharp.Hosting.Identity.Entities.UserLogin", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("TEXT"); - - b.Property("Avatar") - .HasColumnType("TEXT"); - - b.Property("CreatedTime") - .HasColumnType("TEXT"); - - b.Property("LoginProvider") - .HasColumnType("TEXT"); - - b.Property("ProviderDisplayName") - .HasColumnType("TEXT"); - - b.Property("ProviderKey") - .HasColumnType("TEXT"); - - b.Property("UserId") - .HasColumnType("INTEGER"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.HasIndex("LoginProvider", "ProviderKey") - .IsUnique() - .HasName("UserLoginIndex"); - - b.ToTable("Identity_UserLogin"); - }); - - modelBuilder.Entity("OSharp.Hosting.Identity.Entities.UserRole", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("TEXT"); - - b.Property("CreatedTime") - .HasColumnType("TEXT"); - - b.Property("DeletedTime") - .HasColumnType("TEXT"); - - b.Property("IsLocked") - .HasColumnType("INTEGER"); - - b.Property("RoleId") - .HasColumnType("INTEGER"); - - b.Property("UserId") - .HasColumnType("INTEGER"); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.HasIndex("UserId", "RoleId", "DeletedTime") - .IsUnique() - .HasName("UserRoleIndex"); - - b.ToTable("Identity_UserRole"); - }); - - modelBuilder.Entity("OSharp.Hosting.Identity.Entities.UserToken", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("TEXT"); - - b.Property("LoginProvider") - .HasColumnType("TEXT"); - - b.Property("Name") - .HasColumnType("TEXT"); - - b.Property("UserId") - .HasColumnType("INTEGER"); - - b.Property("Value") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.HasIndex("UserId", "LoginProvider", "Name") - .IsUnique() - .HasName("UserTokenIndex"); - - b.ToTable("Identity_UserToken"); - }); - - modelBuilder.Entity("OSharp.Hosting.Infos.Entities.Message", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("TEXT"); - - b.Property("BeginDate") - .HasColumnType("TEXT"); - - b.Property("CanReply") - .HasColumnType("INTEGER"); - - b.Property("Content") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("CreatedTime") - .HasColumnType("TEXT"); - - b.Property("DeletedTime") - .HasColumnType("TEXT"); - - b.Property("EndDate") - .HasColumnType("TEXT"); - - b.Property("IsLocked") - .HasColumnType("INTEGER"); - - b.Property("IsSended") - .HasColumnType("INTEGER"); - - b.Property("MessageType") - .HasColumnType("INTEGER"); - - b.Property("NewReplyCount") - .HasColumnType("INTEGER"); - - b.Property("SenderId") - .HasColumnType("INTEGER"); - - b.Property("Title") - .IsRequired() - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.HasIndex("SenderId"); - - b.ToTable("Infos_Message"); - }); - - modelBuilder.Entity("OSharp.Hosting.Infos.Entities.MessageReceive", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("TEXT"); - - b.Property("CreatedTime") - .HasColumnType("TEXT"); - - b.Property("MessageId") - .HasColumnType("TEXT"); - - b.Property("NewReplyCount") - .HasColumnType("INTEGER"); - - b.Property("ReadDate") - .HasColumnType("TEXT"); - - b.Property("UserId") - .HasColumnType("INTEGER"); - - b.HasKey("Id"); - - b.HasIndex("MessageId"); - - b.HasIndex("UserId"); - - b.ToTable("Infos_MessageReceive"); - }); - - modelBuilder.Entity("OSharp.Hosting.Infos.Entities.MessageReply", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("TEXT"); - - b.Property("BelongMessageId") - .HasColumnType("TEXT"); - - b.Property("Content") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("CreatedTime") - .HasColumnType("TEXT"); - - b.Property("DeletedTime") - .HasColumnType("TEXT"); - - b.Property("IsLocked") - .HasColumnType("INTEGER"); - - b.Property("IsRead") - .HasColumnType("INTEGER"); - - b.Property("ParentMessageId") - .HasColumnType("TEXT"); - - b.Property("ParentReplyId") - .HasColumnType("TEXT"); - - b.Property("UserId") - .HasColumnType("INTEGER"); - - b.HasKey("Id"); - - b.HasIndex("BelongMessageId"); - - b.HasIndex("ParentMessageId"); - - b.HasIndex("ParentReplyId"); - - b.HasIndex("UserId"); - - b.ToTable("Infos_MessageReply"); - }); - - modelBuilder.Entity("OSharp.Hosting.Systems.Entities.AuditEntity", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("TEXT"); - - b.Property("EntityKey") - .HasColumnType("TEXT"); - - b.Property("Name") - .HasColumnType("TEXT"); - - b.Property("OperateType") - .HasColumnType("INTEGER"); - - b.Property("OperationId") - .HasColumnType("TEXT"); - - b.Property("TypeName") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.HasIndex("OperationId"); - - b.ToTable("Systems_AuditEntity"); - }); - - modelBuilder.Entity("OSharp.Hosting.Systems.Entities.AuditOperation", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("TEXT"); - - b.Property("Browser") - .HasColumnType("TEXT"); - - b.Property("CreatedTime") - .HasColumnType("TEXT"); - - b.Property("Elapsed") - .HasColumnType("INTEGER"); - - b.Property("FunctionName") - .HasColumnType("TEXT"); - - b.Property("Ip") - .HasColumnType("TEXT"); - - b.Property("Message") - .HasColumnType("TEXT"); - - b.Property("NickName") - .HasColumnType("TEXT"); - - b.Property("OperationSystem") - .HasColumnType("TEXT"); - - b.Property("ResultType") - .HasColumnType("INTEGER"); - - b.Property("UserAgent") - .HasColumnType("TEXT"); - - b.Property("UserId") - .HasColumnType("TEXT"); - - b.Property("UserName") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.ToTable("Systems_AuditOperation"); - }); - - modelBuilder.Entity("OSharp.Hosting.Systems.Entities.AuditProperty", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("TEXT"); - - b.Property("AuditEntityId") - .HasColumnType("TEXT"); - - b.Property("DataType") - .HasColumnType("TEXT"); - - b.Property("DisplayName") - .HasColumnType("TEXT"); - - b.Property("FieldName") - .HasColumnType("TEXT"); - - b.Property("NewValue") - .HasColumnType("TEXT"); - - b.Property("OriginalValue") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.HasIndex("AuditEntityId"); - - b.ToTable("Systems_AuditProperty"); - }); - - modelBuilder.Entity("OSharp.Hosting.Authorization.Entities.EntityRole", b => - { - b.HasOne("OSharp.Authorization.EntityInfos.EntityInfo", "EntityInfo") - .WithMany() - .HasForeignKey("EntityId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("OSharp.Hosting.Identity.Entities.Role", "Role") - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("OSharp.Hosting.Authorization.Entities.EntityUser", b => - { - b.HasOne("OSharp.Authorization.EntityInfos.EntityInfo", "EntityInfo") - .WithMany() - .HasForeignKey("EntityId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("OSharp.Hosting.Identity.Entities.User", "User") - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("OSharp.Hosting.Authorization.Entities.Module", b => - { - b.HasOne("OSharp.Hosting.Authorization.Entities.Module", "Parent") - .WithMany("Children") - .HasForeignKey("ParentId"); - }); - - modelBuilder.Entity("OSharp.Hosting.Authorization.Entities.ModuleFunction", b => - { - b.HasOne("OSharp.Authorization.Functions.Function", "Function") - .WithMany() - .HasForeignKey("FunctionId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("OSharp.Hosting.Authorization.Entities.Module", "Module") - .WithMany() - .HasForeignKey("ModuleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("OSharp.Hosting.Authorization.Entities.ModuleRole", b => - { - b.HasOne("OSharp.Hosting.Authorization.Entities.Module", "Module") - .WithMany() - .HasForeignKey("ModuleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("OSharp.Hosting.Identity.Entities.Role", "Role") - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("OSharp.Hosting.Authorization.Entities.ModuleUser", b => - { - b.HasOne("OSharp.Hosting.Authorization.Entities.Module", "Module") - .WithMany() - .HasForeignKey("ModuleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("OSharp.Hosting.Identity.Entities.User", "User") - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("OSharp.Hosting.Identity.Entities.LoginLog", b => - { - b.HasOne("OSharp.Hosting.Identity.Entities.User", "User") - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("OSharp.Hosting.Identity.Entities.Organization", b => - { - b.HasOne("OSharp.Hosting.Identity.Entities.Organization", null) - .WithMany() - .HasForeignKey("ParentId"); - }); - - modelBuilder.Entity("OSharp.Hosting.Identity.Entities.Role", b => - { - b.HasOne("OSharp.Hosting.Infos.Entities.Message", null) - .WithMany("PublicRoles") - .HasForeignKey("MessageId"); - }); - - modelBuilder.Entity("OSharp.Hosting.Identity.Entities.RoleClaim", b => - { - b.HasOne("OSharp.Hosting.Identity.Entities.Role", "Role") - .WithMany("RoleClaims") - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("OSharp.Hosting.Identity.Entities.User", b => - { - b.HasOne("OSharp.Hosting.Infos.Entities.Message", null) - .WithMany("Recipients") - .HasForeignKey("MessageId"); - }); - - modelBuilder.Entity("OSharp.Hosting.Identity.Entities.UserClaim", b => - { - b.HasOne("OSharp.Hosting.Identity.Entities.User", "User") - .WithMany("UserClaims") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("OSharp.Hosting.Identity.Entities.UserDetail", b => - { - b.HasOne("OSharp.Hosting.Identity.Entities.User", "User") - .WithOne("UserDetail") - .HasForeignKey("OSharp.Hosting.Identity.Entities.UserDetail", "UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("OSharp.Hosting.Identity.Entities.UserLogin", b => - { - b.HasOne("OSharp.Hosting.Identity.Entities.User", "User") - .WithMany("UserLogins") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("OSharp.Hosting.Identity.Entities.UserRole", b => - { - b.HasOne("OSharp.Hosting.Identity.Entities.Role", "Role") - .WithMany("UserRoles") - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("OSharp.Hosting.Identity.Entities.User", "User") - .WithMany("UserRoles") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("OSharp.Hosting.Identity.Entities.UserToken", b => - { - b.HasOne("OSharp.Hosting.Identity.Entities.User", "User") - .WithMany("UserTokens") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("OSharp.Hosting.Infos.Entities.Message", b => - { - b.HasOne("OSharp.Hosting.Identity.Entities.User", "Sender") - .WithMany() - .HasForeignKey("SenderId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("OSharp.Hosting.Infos.Entities.MessageReceive", b => - { - b.HasOne("OSharp.Hosting.Infos.Entities.Message", "Message") - .WithMany("Receives") - .HasForeignKey("MessageId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("OSharp.Hosting.Identity.Entities.User", "User") - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - }); - - modelBuilder.Entity("OSharp.Hosting.Infos.Entities.MessageReply", b => - { - b.HasOne("OSharp.Hosting.Infos.Entities.Message", "BelongMessage") - .WithMany() - .HasForeignKey("BelongMessageId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.HasOne("OSharp.Hosting.Infos.Entities.Message", "ParentMessage") - .WithMany("Replies") - .HasForeignKey("ParentMessageId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.HasOne("OSharp.Hosting.Infos.Entities.MessageReply", "ParentReply") - .WithMany("Replies") - .HasForeignKey("ParentReplyId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.HasOne("OSharp.Hosting.Identity.Entities.User", "User") - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - }); - - modelBuilder.Entity("OSharp.Hosting.Systems.Entities.AuditEntity", b => - { - b.HasOne("OSharp.Hosting.Systems.Entities.AuditOperation", "Operation") - .WithMany("AuditEntities") - .HasForeignKey("OperationId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("OSharp.Hosting.Systems.Entities.AuditProperty", b => - { - b.HasOne("OSharp.Hosting.Systems.Entities.AuditEntity", "AuditEntity") - .WithMany("Properties") - .HasForeignKey("AuditEntityId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/samples/web/Liuliu.Demo.WebApi/Migrations/20210305130944_Menu.cs b/samples/web/Liuliu.Demo.WebApi/Migrations/20210305130944_Menu.cs deleted file mode 100644 index 4d9eb639c..000000000 --- a/samples/web/Liuliu.Demo.WebApi/Migrations/20210305130944_Menu.cs +++ /dev/null @@ -1,51 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -namespace Liuliu.Demo.Web.Migrations -{ - public partial class Menu : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Systems_Menu", - columns: table => new - { - Id = table.Column(type: "INTEGER", nullable: false) - .Annotation("Sqlite:Autoincrement", true), - Name = table.Column(type: "TEXT", maxLength: 500, nullable: false), - Text = table.Column(type: "TEXT", maxLength: 500, nullable: false), - Icon = table.Column(type: "TEXT", maxLength: 50, nullable: true), - Url = table.Column(type: "TEXT", maxLength: 2000, nullable: true), - Target = table.Column(type: "TEXT", maxLength: 50, nullable: true), - Acl = table.Column(type: "TEXT", maxLength: 500, nullable: true), - OrderCode = table.Column(type: "REAL", nullable: false), - Data = table.Column(type: "TEXT", maxLength: 1000, nullable: true), - TreePathString = table.Column(type: "TEXT", maxLength: 1000, nullable: true), - IsEnabled = table.Column(type: "INTEGER", nullable: false), - IsSystem = table.Column(type: "INTEGER", nullable: false), - ParentId = table.Column(type: "INTEGER", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Systems_Menu", x => x.Id); - table.ForeignKey( - name: "FK_Systems_Menu_Systems_Menu_ParentId", - column: x => x.ParentId, - principalTable: "Systems_Menu", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - }); - - migrationBuilder.CreateIndex( - name: "IX_Systems_Menu_ParentId", - table: "Systems_Menu", - column: "ParentId"); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Systems_Menu"); - } - } -} diff --git a/samples/web/Liuliu.Demo.WebApi/Migrations/20210305130944_Menu.Designer.cs b/samples/web/Liuliu.Demo.WebApi/Migrations/20210318164423_Init.Designer.cs similarity index 99% rename from samples/web/Liuliu.Demo.WebApi/Migrations/20210305130944_Menu.Designer.cs rename to samples/web/Liuliu.Demo.WebApi/Migrations/20210318164423_Init.Designer.cs index a44b85883..93c70dea1 100644 --- a/samples/web/Liuliu.Demo.WebApi/Migrations/20210305130944_Menu.Designer.cs +++ b/samples/web/Liuliu.Demo.WebApi/Migrations/20210318164423_Init.Designer.cs @@ -9,14 +9,14 @@ namespace Liuliu.Demo.Web.Migrations { [DbContext(typeof(DefaultDbContext))] - [Migration("20210305130944_Menu")] - partial class Menu + [Migration("20210318164423_Init")] + partial class Init { protected override void BuildTargetModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "5.0.3"); + .HasAnnotation("ProductVersion", "5.0.4"); modelBuilder.Entity("OSharp.Authorization.EntityInfos.EntityInfo", b => { diff --git a/samples/web/Liuliu.Demo.WebApi/Migrations/20201116154409_Init.cs b/samples/web/Liuliu.Demo.WebApi/Migrations/20210318164423_Init.cs similarity index 62% rename from samples/web/Liuliu.Demo.WebApi/Migrations/20201116154409_Init.cs rename to samples/web/Liuliu.Demo.WebApi/Migrations/20210318164423_Init.cs index 23c45393d..abe3ffec8 100644 --- a/samples/web/Liuliu.Demo.WebApi/Migrations/20201116154409_Init.cs +++ b/samples/web/Liuliu.Demo.WebApi/Migrations/20210318164423_Init.cs @@ -11,11 +11,11 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "Auth_EntityInfo", columns: table => new { - Id = table.Column(nullable: false), - Name = table.Column(nullable: false), - TypeName = table.Column(nullable: false), - AuditEnabled = table.Column(nullable: false), - PropertyJson = table.Column(nullable: false) + Id = table.Column(type: "TEXT", nullable: false), + Name = table.Column(type: "TEXT", nullable: false), + TypeName = table.Column(type: "TEXT", nullable: false), + AuditEnabled = table.Column(type: "INTEGER", nullable: false), + PropertyJson = table.Column(type: "TEXT", nullable: false) }, constraints: table => { @@ -26,20 +26,20 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "Auth_Function", columns: table => new { - Id = table.Column(nullable: false), - Name = table.Column(nullable: true), - Area = table.Column(nullable: true), - Controller = table.Column(nullable: true), - Action = table.Column(nullable: true), - IsController = table.Column(nullable: false), - IsAjax = table.Column(nullable: false), - AccessType = table.Column(nullable: false), - IsAccessTypeChanged = table.Column(nullable: false), - AuditOperationEnabled = table.Column(nullable: false), - AuditEntityEnabled = table.Column(nullable: false), - CacheExpirationSeconds = table.Column(nullable: false), - IsCacheSliding = table.Column(nullable: false), - IsLocked = table.Column(nullable: false) + Id = table.Column(type: "TEXT", nullable: false), + Name = table.Column(type: "TEXT", nullable: true), + Area = table.Column(type: "TEXT", nullable: true), + Controller = table.Column(type: "TEXT", nullable: true), + Action = table.Column(type: "TEXT", nullable: true), + IsController = table.Column(type: "INTEGER", nullable: false), + IsAjax = table.Column(type: "INTEGER", nullable: false), + AccessType = table.Column(type: "INTEGER", nullable: false), + IsAccessTypeChanged = table.Column(type: "INTEGER", nullable: false), + AuditOperationEnabled = table.Column(type: "INTEGER", nullable: false), + AuditEntityEnabled = table.Column(type: "INTEGER", nullable: false), + CacheExpirationSeconds = table.Column(type: "INTEGER", nullable: false), + IsCacheSliding = table.Column(type: "INTEGER", nullable: false), + IsLocked = table.Column(type: "INTEGER", nullable: false) }, constraints: table => { @@ -50,14 +50,14 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "Auth_Module", columns: table => new { - Id = table.Column(nullable: false) + Id = table.Column(type: "INTEGER", nullable: false) .Annotation("Sqlite:Autoincrement", true), - Name = table.Column(nullable: false), - Remark = table.Column(nullable: true), - Code = table.Column(nullable: false), - OrderCode = table.Column(nullable: false), - TreePathString = table.Column(nullable: true), - ParentId = table.Column(nullable: true) + Name = table.Column(type: "TEXT", nullable: false), + Remark = table.Column(type: "TEXT", nullable: true), + Code = table.Column(type: "TEXT", nullable: false), + OrderCode = table.Column(type: "REAL", nullable: false), + TreePathString = table.Column(type: "TEXT", nullable: true), + ParentId = table.Column(type: "INTEGER", nullable: true) }, constraints: table => { @@ -74,11 +74,11 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "Identity_Organization", columns: table => new { - Id = table.Column(nullable: false) + Id = table.Column(type: "INTEGER", nullable: false) .Annotation("Sqlite:Autoincrement", true), - Name = table.Column(nullable: false), - Remark = table.Column(nullable: true), - ParentId = table.Column(nullable: true) + Name = table.Column(type: "TEXT", nullable: false), + Remark = table.Column(type: "TEXT", nullable: true), + ParentId = table.Column(type: "INTEGER", nullable: true) }, constraints: table => { @@ -95,19 +95,19 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "Systems_AuditOperation", columns: table => new { - Id = table.Column(nullable: false), - FunctionName = table.Column(nullable: true), - UserId = table.Column(nullable: true), - UserName = table.Column(nullable: true), - NickName = table.Column(nullable: true), - Ip = table.Column(nullable: true), - OperationSystem = table.Column(nullable: true), - Browser = table.Column(nullable: true), - UserAgent = table.Column(nullable: true), - ResultType = table.Column(nullable: false), - Message = table.Column(nullable: true), - Elapsed = table.Column(nullable: false), - CreatedTime = table.Column(nullable: false) + Id = table.Column(type: "TEXT", nullable: false), + FunctionName = table.Column(type: "TEXT", nullable: true), + UserId = table.Column(type: "TEXT", nullable: true), + UserName = table.Column(type: "TEXT", nullable: true), + NickName = table.Column(type: "TEXT", nullable: true), + Ip = table.Column(type: "TEXT", nullable: true), + OperationSystem = table.Column(type: "TEXT", nullable: true), + Browser = table.Column(type: "TEXT", nullable: true), + UserAgent = table.Column(type: "TEXT", nullable: true), + ResultType = table.Column(type: "INTEGER", nullable: false), + Message = table.Column(type: "TEXT", nullable: true), + Elapsed = table.Column(type: "INTEGER", nullable: false), + CreatedTime = table.Column(type: "TEXT", nullable: false) }, constraints: table => { @@ -118,24 +118,54 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "Systems_KeyValue", columns: table => new { - Id = table.Column(nullable: false), - ValueJson = table.Column(nullable: true), - ValueType = table.Column(nullable: true), - Key = table.Column(nullable: false), - IsLocked = table.Column(nullable: false) + Id = table.Column(type: "TEXT", nullable: false), + ValueJson = table.Column(type: "TEXT", nullable: true), + ValueType = table.Column(type: "TEXT", nullable: true), + Key = table.Column(type: "TEXT", nullable: false), + IsLocked = table.Column(type: "INTEGER", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Systems_KeyValue", x => x.Id); }); + migrationBuilder.CreateTable( + name: "Systems_Menu", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Name = table.Column(type: "TEXT", maxLength: 500, nullable: false), + Text = table.Column(type: "TEXT", maxLength: 500, nullable: false), + Icon = table.Column(type: "TEXT", maxLength: 50, nullable: true), + Url = table.Column(type: "TEXT", maxLength: 2000, nullable: true), + Target = table.Column(type: "TEXT", maxLength: 50, nullable: true), + Acl = table.Column(type: "TEXT", maxLength: 500, nullable: true), + OrderCode = table.Column(type: "REAL", nullable: false), + Data = table.Column(type: "TEXT", maxLength: 1000, nullable: true), + TreePathString = table.Column(type: "TEXT", maxLength: 1000, nullable: true), + IsEnabled = table.Column(type: "INTEGER", nullable: false), + IsSystem = table.Column(type: "INTEGER", nullable: false), + ParentId = table.Column(type: "INTEGER", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Systems_Menu", x => x.Id); + table.ForeignKey( + name: "FK_Systems_Menu_Systems_Menu_ParentId", + column: x => x.ParentId, + principalTable: "Systems_Menu", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + migrationBuilder.CreateTable( name: "Auth_ModuleFunction", columns: table => new { - Id = table.Column(nullable: false), - ModuleId = table.Column(nullable: false), - FunctionId = table.Column(nullable: false) + Id = table.Column(type: "TEXT", nullable: false), + ModuleId = table.Column(type: "INTEGER", nullable: false), + FunctionId = table.Column(type: "TEXT", nullable: false) }, constraints: table => { @@ -158,12 +188,12 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "Systems_AuditEntity", columns: table => new { - Id = table.Column(nullable: false), - Name = table.Column(nullable: true), - TypeName = table.Column(nullable: true), - EntityKey = table.Column(nullable: true), - OperateType = table.Column(nullable: false), - OperationId = table.Column(nullable: false) + Id = table.Column(type: "TEXT", nullable: false), + Name = table.Column(type: "TEXT", nullable: true), + TypeName = table.Column(type: "TEXT", nullable: true), + EntityKey = table.Column(type: "TEXT", nullable: true), + OperateType = table.Column(type: "INTEGER", nullable: false), + OperationId = table.Column(type: "TEXT", nullable: false) }, constraints: table => { @@ -180,13 +210,13 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "Systems_AuditProperty", columns: table => new { - Id = table.Column(nullable: false), - DisplayName = table.Column(nullable: true), - FieldName = table.Column(nullable: true), - OriginalValue = table.Column(nullable: true), - NewValue = table.Column(nullable: true), - DataType = table.Column(nullable: true), - AuditEntityId = table.Column(nullable: false) + Id = table.Column(type: "TEXT", nullable: false), + DisplayName = table.Column(type: "TEXT", nullable: true), + FieldName = table.Column(type: "TEXT", nullable: true), + OriginalValue = table.Column(type: "TEXT", nullable: true), + NewValue = table.Column(type: "TEXT", nullable: true), + DataType = table.Column(type: "TEXT", nullable: true), + AuditEntityId = table.Column(type: "TEXT", nullable: false) }, constraints: table => { @@ -203,13 +233,13 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "Auth_EntityRole", columns: table => new { - Id = table.Column(nullable: false), - RoleId = table.Column(nullable: false), - EntityId = table.Column(nullable: false), - Operation = table.Column(nullable: false), - FilterGroupJson = table.Column(nullable: true), - IsLocked = table.Column(nullable: false), - CreatedTime = table.Column(nullable: false) + Id = table.Column(type: "TEXT", nullable: false), + RoleId = table.Column(type: "INTEGER", nullable: false), + EntityId = table.Column(type: "TEXT", nullable: false), + Operation = table.Column(type: "INTEGER", nullable: false), + FilterGroupJson = table.Column(type: "TEXT", nullable: true), + IsLocked = table.Column(type: "INTEGER", nullable: false), + CreatedTime = table.Column(type: "TEXT", nullable: false) }, constraints: table => { @@ -226,12 +256,12 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "Auth_EntityUser", columns: table => new { - Id = table.Column(nullable: false), - UserId = table.Column(nullable: false), - EntityId = table.Column(nullable: false), - FilterGroupJson = table.Column(nullable: true), - IsLocked = table.Column(nullable: false), - CreatedTime = table.Column(nullable: false) + Id = table.Column(type: "TEXT", nullable: false), + UserId = table.Column(type: "INTEGER", nullable: false), + EntityId = table.Column(type: "TEXT", nullable: false), + FilterGroupJson = table.Column(type: "TEXT", nullable: true), + IsLocked = table.Column(type: "INTEGER", nullable: false), + CreatedTime = table.Column(type: "TEXT", nullable: false) }, constraints: table => { @@ -248,9 +278,9 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "Auth_ModuleRole", columns: table => new { - Id = table.Column(nullable: false), - ModuleId = table.Column(nullable: false), - RoleId = table.Column(nullable: false) + Id = table.Column(type: "TEXT", nullable: false), + ModuleId = table.Column(type: "INTEGER", nullable: false), + RoleId = table.Column(type: "INTEGER", nullable: false) }, constraints: table => { @@ -267,10 +297,10 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "Auth_ModuleUser", columns: table => new { - Id = table.Column(nullable: false), - ModuleId = table.Column(nullable: false), - UserId = table.Column(nullable: false), - Disabled = table.Column(nullable: false) + Id = table.Column(type: "TEXT", nullable: false), + ModuleId = table.Column(type: "INTEGER", nullable: false), + UserId = table.Column(type: "INTEGER", nullable: false), + Disabled = table.Column(type: "INTEGER", nullable: false) }, constraints: table => { @@ -287,11 +317,11 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "Identity_RoleClaim", columns: table => new { - Id = table.Column(nullable: false) + Id = table.Column(type: "INTEGER", nullable: false) .Annotation("Sqlite:Autoincrement", true), - RoleId = table.Column(nullable: false), - ClaimType = table.Column(nullable: true), - ClaimValue = table.Column(nullable: true) + RoleId = table.Column(type: "INTEGER", nullable: false), + ClaimType = table.Column(type: "TEXT", nullable: true), + ClaimValue = table.Column(type: "TEXT", nullable: true) }, constraints: table => { @@ -302,12 +332,12 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "Identity_UserRole", columns: table => new { - Id = table.Column(nullable: false), - UserId = table.Column(nullable: false), - RoleId = table.Column(nullable: false), - CreatedTime = table.Column(nullable: false), - IsLocked = table.Column(nullable: false), - DeletedTime = table.Column(nullable: true) + Id = table.Column(type: "TEXT", nullable: false), + UserId = table.Column(type: "INTEGER", nullable: false), + RoleId = table.Column(type: "INTEGER", nullable: false), + CreatedTime = table.Column(type: "TEXT", nullable: false), + IsLocked = table.Column(type: "INTEGER", nullable: false), + DeletedTime = table.Column(type: "TEXT", nullable: true) }, constraints: table => { @@ -318,12 +348,12 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "Identity_LoginLog", columns: table => new { - Id = table.Column(nullable: false), - Ip = table.Column(nullable: true), - UserAgent = table.Column(nullable: true), - LogoutTime = table.Column(nullable: true), - CreatedTime = table.Column(nullable: false), - UserId = table.Column(nullable: false) + Id = table.Column(type: "TEXT", nullable: false), + Ip = table.Column(type: "TEXT", nullable: true), + UserAgent = table.Column(type: "TEXT", nullable: true), + LogoutTime = table.Column(type: "TEXT", nullable: true), + CreatedTime = table.Column(type: "TEXT", nullable: false), + UserId = table.Column(type: "INTEGER", nullable: false) }, constraints: table => { @@ -334,11 +364,11 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "Identity_UserClaim", columns: table => new { - Id = table.Column(nullable: false) + Id = table.Column(type: "INTEGER", nullable: false) .Annotation("Sqlite:Autoincrement", true), - UserId = table.Column(nullable: false), - ClaimType = table.Column(nullable: false), - ClaimValue = table.Column(nullable: true) + UserId = table.Column(type: "INTEGER", nullable: false), + ClaimType = table.Column(type: "TEXT", nullable: false), + ClaimValue = table.Column(type: "TEXT", nullable: true) }, constraints: table => { @@ -349,10 +379,10 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "Identity_UserDetail", columns: table => new { - Id = table.Column(nullable: false) + Id = table.Column(type: "INTEGER", nullable: false) .Annotation("Sqlite:Autoincrement", true), - RegisterIp = table.Column(nullable: true), - UserId = table.Column(nullable: false) + RegisterIp = table.Column(type: "TEXT", nullable: true), + UserId = table.Column(type: "INTEGER", nullable: false) }, constraints: table => { @@ -363,13 +393,13 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "Identity_UserLogin", columns: table => new { - Id = table.Column(nullable: false), - LoginProvider = table.Column(nullable: true), - ProviderKey = table.Column(nullable: true), - ProviderDisplayName = table.Column(nullable: true), - Avatar = table.Column(nullable: true), - UserId = table.Column(nullable: false), - CreatedTime = table.Column(nullable: false) + Id = table.Column(type: "TEXT", nullable: false), + LoginProvider = table.Column(type: "TEXT", nullable: true), + ProviderKey = table.Column(type: "TEXT", nullable: true), + ProviderDisplayName = table.Column(type: "TEXT", nullable: true), + Avatar = table.Column(type: "TEXT", nullable: true), + UserId = table.Column(type: "INTEGER", nullable: false), + CreatedTime = table.Column(type: "TEXT", nullable: false) }, constraints: table => { @@ -380,11 +410,11 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "Identity_UserToken", columns: table => new { - Id = table.Column(nullable: false), - UserId = table.Column(nullable: false), - LoginProvider = table.Column(nullable: true), - Name = table.Column(nullable: true), - Value = table.Column(nullable: true) + Id = table.Column(type: "TEXT", nullable: false), + UserId = table.Column(type: "INTEGER", nullable: false), + LoginProvider = table.Column(type: "TEXT", nullable: true), + Name = table.Column(type: "TEXT", nullable: true), + Value = table.Column(type: "TEXT", nullable: true) }, constraints: table => { @@ -395,19 +425,19 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "Infos_Message", columns: table => new { - Id = table.Column(nullable: false), - Title = table.Column(nullable: false), - Content = table.Column(nullable: false), - MessageType = table.Column(nullable: false), - NewReplyCount = table.Column(nullable: false), - IsSended = table.Column(nullable: false), - CanReply = table.Column(nullable: false), - BeginDate = table.Column(nullable: true), - EndDate = table.Column(nullable: true), - IsLocked = table.Column(nullable: false), - DeletedTime = table.Column(nullable: true), - CreatedTime = table.Column(nullable: false), - SenderId = table.Column(nullable: false) + Id = table.Column(type: "TEXT", nullable: false), + Title = table.Column(type: "TEXT", nullable: false), + Content = table.Column(type: "TEXT", nullable: false), + MessageType = table.Column(type: "INTEGER", nullable: false), + NewReplyCount = table.Column(type: "INTEGER", nullable: false), + IsSended = table.Column(type: "INTEGER", nullable: false), + CanReply = table.Column(type: "INTEGER", nullable: false), + BeginDate = table.Column(type: "TEXT", nullable: true), + EndDate = table.Column(type: "TEXT", nullable: true), + IsLocked = table.Column(type: "INTEGER", nullable: false), + DeletedTime = table.Column(type: "TEXT", nullable: true), + CreatedTime = table.Column(type: "TEXT", nullable: false), + SenderId = table.Column(type: "INTEGER", nullable: false) }, constraints: table => { @@ -418,19 +448,19 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "Identity_Role", columns: table => new { - Id = table.Column(nullable: false) + Id = table.Column(type: "INTEGER", nullable: false) .Annotation("Sqlite:Autoincrement", true), - Name = table.Column(nullable: false), - NormalizedName = table.Column(nullable: false), - ConcurrencyStamp = table.Column(nullable: true), - Remark = table.Column(maxLength: 512, nullable: true), - IsAdmin = table.Column(nullable: false), - IsDefault = table.Column(nullable: false), - IsSystem = table.Column(nullable: false), - IsLocked = table.Column(nullable: false), - CreatedTime = table.Column(nullable: false), - DeletedTime = table.Column(nullable: true), - MessageId = table.Column(nullable: true) + MessageId = table.Column(type: "TEXT", nullable: true), + Name = table.Column(type: "TEXT", nullable: false), + NormalizedName = table.Column(type: "TEXT", nullable: false), + ConcurrencyStamp = table.Column(type: "TEXT", nullable: true), + Remark = table.Column(type: "TEXT", maxLength: 512, nullable: true), + IsAdmin = table.Column(type: "INTEGER", nullable: false), + IsDefault = table.Column(type: "INTEGER", nullable: false), + IsSystem = table.Column(type: "INTEGER", nullable: false), + IsLocked = table.Column(type: "INTEGER", nullable: false), + CreatedTime = table.Column(type: "TEXT", nullable: false), + DeletedTime = table.Column(type: "TEXT", nullable: true) }, constraints: table => { @@ -447,30 +477,30 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "Identity_User", columns: table => new { - Id = table.Column(nullable: false) + Id = table.Column(type: "INTEGER", nullable: false) .Annotation("Sqlite:Autoincrement", true), - UserName = table.Column(nullable: false), - NormalizedUserName = table.Column(nullable: false), - NickName = table.Column(nullable: true), - Email = table.Column(nullable: true), - NormalizeEmail = table.Column(nullable: true), - EmailConfirmed = table.Column(nullable: false), - PasswordHash = table.Column(nullable: true), - HeadImg = table.Column(nullable: true), - SecurityStamp = table.Column(nullable: true), - ConcurrencyStamp = table.Column(nullable: true), - PhoneNumber = table.Column(nullable: true), - PhoneNumberConfirmed = table.Column(nullable: false), - TwoFactorEnabled = table.Column(nullable: false), - LockoutEnd = table.Column(nullable: true), - LockoutEnabled = table.Column(nullable: false), - AccessFailedCount = table.Column(nullable: false), - IsSystem = table.Column(nullable: false), - IsLocked = table.Column(nullable: false), - CreatedTime = table.Column(nullable: false), - DeletedTime = table.Column(nullable: true), - Remark = table.Column(nullable: true), - MessageId = table.Column(nullable: true) + Remark = table.Column(type: "TEXT", nullable: true), + MessageId = table.Column(type: "TEXT", nullable: true), + UserName = table.Column(type: "TEXT", nullable: false), + NormalizedUserName = table.Column(type: "TEXT", nullable: false), + NickName = table.Column(type: "TEXT", nullable: true), + Email = table.Column(type: "TEXT", nullable: true), + NormalizeEmail = table.Column(type: "TEXT", nullable: true), + EmailConfirmed = table.Column(type: "INTEGER", nullable: false), + PasswordHash = table.Column(type: "TEXT", nullable: true), + HeadImg = table.Column(type: "TEXT", nullable: true), + SecurityStamp = table.Column(type: "TEXT", nullable: true), + ConcurrencyStamp = table.Column(type: "TEXT", nullable: true), + PhoneNumber = table.Column(type: "TEXT", nullable: true), + PhoneNumberConfirmed = table.Column(type: "INTEGER", nullable: false), + TwoFactorEnabled = table.Column(type: "INTEGER", nullable: false), + LockoutEnd = table.Column(type: "TEXT", nullable: true), + LockoutEnabled = table.Column(type: "INTEGER", nullable: false), + AccessFailedCount = table.Column(type: "INTEGER", nullable: false), + IsSystem = table.Column(type: "INTEGER", nullable: false), + IsLocked = table.Column(type: "INTEGER", nullable: false), + CreatedTime = table.Column(type: "TEXT", nullable: false), + DeletedTime = table.Column(type: "TEXT", nullable: true) }, constraints: table => { @@ -487,48 +517,54 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "Infos_MessageReceive", columns: table => new { - Id = table.Column(nullable: false), - ReadDate = table.Column(nullable: false), - NewReplyCount = table.Column(nullable: false), - CreatedTime = table.Column(nullable: false), - MessageId = table.Column(nullable: false), - UserId = table.Column(nullable: false) + Id = table.Column(type: "TEXT", nullable: false), + ReadDate = table.Column(type: "TEXT", nullable: false), + NewReplyCount = table.Column(type: "INTEGER", nullable: false), + CreatedTime = table.Column(type: "TEXT", nullable: false), + MessageId = table.Column(type: "TEXT", nullable: false), + UserId = table.Column(type: "INTEGER", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Infos_MessageReceive", x => x.Id); - table.ForeignKey( - name: "FK_Infos_MessageReceive_Infos_Message_MessageId", - column: x => x.MessageId, - principalTable: "Infos_Message", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Infos_MessageReceive_Identity_User_UserId", column: x => x.UserId, principalTable: "Identity_User", principalColumn: "Id", onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_Infos_MessageReceive_Infos_Message_MessageId", + column: x => x.MessageId, + principalTable: "Infos_Message", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Infos_MessageReply", columns: table => new { - Id = table.Column(nullable: false), - Content = table.Column(nullable: false), - IsRead = table.Column(nullable: false), - ParentMessageId = table.Column(nullable: false), - ParentReplyId = table.Column(nullable: false), - IsLocked = table.Column(nullable: false), - DeletedTime = table.Column(nullable: true), - CreatedTime = table.Column(nullable: false), - UserId = table.Column(nullable: false), - BelongMessageId = table.Column(nullable: false) + Id = table.Column(type: "TEXT", nullable: false), + Content = table.Column(type: "TEXT", nullable: false), + IsRead = table.Column(type: "INTEGER", nullable: false), + ParentMessageId = table.Column(type: "TEXT", nullable: false), + ParentReplyId = table.Column(type: "TEXT", nullable: false), + IsLocked = table.Column(type: "INTEGER", nullable: false), + DeletedTime = table.Column(type: "TEXT", nullable: true), + CreatedTime = table.Column(type: "TEXT", nullable: false), + UserId = table.Column(type: "INTEGER", nullable: false), + BelongMessageId = table.Column(type: "TEXT", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Infos_MessageReply", x => x.Id); + table.ForeignKey( + name: "FK_Infos_MessageReply_Identity_User_UserId", + column: x => x.UserId, + principalTable: "Identity_User", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_Infos_MessageReply_Infos_Message_BelongMessageId", column: x => x.BelongMessageId, @@ -547,12 +583,6 @@ protected override void Up(MigrationBuilder migrationBuilder) principalTable: "Infos_MessageReply", principalColumn: "Id", onDelete: ReferentialAction.Restrict); - table.ForeignKey( - name: "FK_Infos_MessageReply_Identity_User_UserId", - column: x => x.UserId, - principalTable: "Identity_User", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateIndex( @@ -561,11 +591,6 @@ protected override void Up(MigrationBuilder migrationBuilder) column: "TypeName", unique: true); - migrationBuilder.CreateIndex( - name: "IX_Auth_EntityRole_RoleId", - table: "Auth_EntityRole", - column: "RoleId"); - migrationBuilder.CreateIndex( name: "EntityRoleIndex", table: "Auth_EntityRole", @@ -573,15 +598,20 @@ protected override void Up(MigrationBuilder migrationBuilder) unique: true); migrationBuilder.CreateIndex( - name: "IX_Auth_EntityUser_UserId", - table: "Auth_EntityUser", - column: "UserId"); + name: "IX_Auth_EntityRole_RoleId", + table: "Auth_EntityRole", + column: "RoleId"); migrationBuilder.CreateIndex( name: "EntityUserIndex", table: "Auth_EntityUser", columns: new[] { "EntityId", "UserId" }); + migrationBuilder.CreateIndex( + name: "IX_Auth_EntityUser_UserId", + table: "Auth_EntityUser", + column: "UserId"); + migrationBuilder.CreateIndex( name: "AreaControllerActionIndex", table: "Auth_Function", @@ -653,14 +683,14 @@ protected override void Up(MigrationBuilder migrationBuilder) column: "RoleId"); migrationBuilder.CreateIndex( - name: "IX_Identity_User_MessageId", + name: "EmailIndex", table: "Identity_User", - column: "MessageId"); + columns: new[] { "NormalizeEmail", "DeletedTime" }); migrationBuilder.CreateIndex( - name: "EmailIndex", + name: "IX_Identity_User_MessageId", table: "Identity_User", - columns: new[] { "NormalizeEmail", "DeletedTime" }); + column: "MessageId"); migrationBuilder.CreateIndex( name: "UserNameIndex", @@ -752,6 +782,11 @@ protected override void Up(MigrationBuilder migrationBuilder) table: "Systems_AuditProperty", column: "AuditEntityId"); + migrationBuilder.CreateIndex( + name: "IX_Systems_Menu_ParentId", + table: "Systems_Menu", + column: "ParentId"); + migrationBuilder.AddForeignKey( name: "FK_Auth_EntityRole_Identity_Role_RoleId", table: "Auth_EntityRole", @@ -914,6 +949,9 @@ protected override void Down(MigrationBuilder migrationBuilder) migrationBuilder.DropTable( name: "Systems_KeyValue"); + migrationBuilder.DropTable( + name: "Systems_Menu"); + migrationBuilder.DropTable( name: "Auth_EntityInfo"); diff --git a/samples/web/Liuliu.Demo.WebApi/Migrations/DefaultDbContextModelSnapshot.cs b/samples/web/Liuliu.Demo.WebApi/Migrations/DefaultDbContextModelSnapshot.cs index 84c4a080f..7f080cd97 100644 --- a/samples/web/Liuliu.Demo.WebApi/Migrations/DefaultDbContextModelSnapshot.cs +++ b/samples/web/Liuliu.Demo.WebApi/Migrations/DefaultDbContextModelSnapshot.cs @@ -14,7 +14,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "5.0.3"); + .HasAnnotation("ProductVersion", "5.0.4"); modelBuilder.Entity("OSharp.Authorization.EntityInfos.EntityInfo", b => { diff --git a/src/OSharp.AspNetCore/Mvc/Filters/AuditOperationAttribute.cs b/src/OSharp.AspNetCore/Mvc/Filters/AuditOperationAttribute.cs index e88a605cc..2cbc43d3e 100644 --- a/src/OSharp.AspNetCore/Mvc/Filters/AuditOperationAttribute.cs +++ b/src/OSharp.AspNetCore/Mvc/Filters/AuditOperationAttribute.cs @@ -77,15 +77,16 @@ public override void OnResultExecuted(ResultExecutedContext context) return; } dict.AuditOperation.EndedTime = DateTime.Now; - IUnitOfWork unitOfWork = provider.GetUnitOfWork(); - //回滚之前业务处理中的未提交事务,防止审计信息保存时误提交 - unitOfWork?.Rollback(); + IUnitOfWork unitOfWork = provider.GetService(); + unitOfWork?.Dispose(); //移除当前功能,使保存审计信息的时候不再获取记录变更,审计信息不需要再审计 dict.Function = null; IAuditStore store = provider.GetService(); - store?.Save(dict.AuditOperation); - unitOfWork?.Commit(); + provider.BeginUnitOfWorkTransaction(_ => + { + store?.Save(dict.AuditOperation); + }); } } diff --git a/src/OSharp.AspNetCore/Mvc/Filters/UnitOfWorkAttribute.cs b/src/OSharp.AspNetCore/Mvc/Filters/UnitOfWorkAttribute.cs index 596115e85..8ef2729d7 100644 --- a/src/OSharp.AspNetCore/Mvc/Filters/UnitOfWorkAttribute.cs +++ b/src/OSharp.AspNetCore/Mvc/Filters/UnitOfWorkAttribute.cs @@ -11,7 +11,12 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using OSharp.AspNetCore.UI; +using OSharp.Data; +using OSharp.Dependency; using OSharp.Entity; @@ -21,13 +26,107 @@ namespace OSharp.AspNetCore.Mvc.Filters /// 自动事务提交过滤器,在方法中执行进行事务提交 /// [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] - public class UnitOfWorkAttribute : ServiceFilterAttribute + public class UnitOfWorkAttribute : Attribute, IActionFilter { + private IUnitOfWork _unitOfWork; + private ILogger _logger; + /// - /// 初始化一个类型的新实例 + /// Called before the action executes, after model binding is complete. /// - public UnitOfWorkAttribute() - : base(typeof(UnitOfWorkFilterImpl)) - { } + /// The . + public void OnActionExecuting(ActionExecutingContext context) + { + IServiceProvider provider = context.HttpContext.RequestServices; + _logger = provider.GetLogger(); + _unitOfWork = provider.GetUnitOfWork(true); + } + + /// + /// Called after the action executes, before the action result. + /// + /// The . + public void OnActionExecuted(ActionExecutedContext context) + { + ScopedDictionary dict = context.HttpContext.RequestServices.GetService(); + AjaxResultType type = AjaxResultType.Success; + string message = null; + if (context.Exception != null && !context.ExceptionHandled) + { + Exception ex = context.Exception; + _logger.LogError(new EventId(), ex, ex.Message); + message = ex.Message; + if (context.HttpContext.Request.IsAjaxRequest() || context.HttpContext.Request.IsJsonContextType()) + { + if (!context.HttpContext.Response.HasStarted) + { + context.Result = new JsonResult(new AjaxResult(ex.Message, AjaxResultType.Error)); + } + context.ExceptionHandled = true; + } + } + if (context.Result is JsonResult result1) + { + if (result1.Value is AjaxResult ajax) + { + type = ajax.Type; + message = ajax.Content; + if (ajax.Succeeded()) + { + _unitOfWork?.Commit(); + } + } + } + else if (context.Result is ObjectResult result2) + { + if (result2.Value is AjaxResult ajax) + { + type = ajax.Type; + message = ajax.Content; + if (ajax.Succeeded()) + { + _unitOfWork?.Commit(); + } + } + else + { + _unitOfWork?.Commit(); + } + } + //普通请求 + else if (context.HttpContext.Response.StatusCode >= 400) + { + switch (context.HttpContext.Response.StatusCode) + { + case 401: + type = AjaxResultType.UnAuth; + break; + case 403: + type = AjaxResultType.UnAuth; + break; + case 404: + type = AjaxResultType.UnAuth; + break; + case 423: + type = AjaxResultType.UnAuth; + break; + default: + type = AjaxResultType.Error; + break; + } + } + else + { + type = AjaxResultType.Success; + _unitOfWork?.Commit(); + } + + if (dict.AuditOperation != null) + { + dict.AuditOperation.ResultType = type; + dict.AuditOperation.Message = message; + } + } + } } \ No newline at end of file diff --git a/src/OSharp.AspNetCore/Mvc/Filters/UnitOfWorkFilterImpl.cs b/src/OSharp.AspNetCore/Mvc/Filters/UnitOfWorkFilterImpl.cs deleted file mode 100644 index 5bdb902a6..000000000 --- a/src/OSharp.AspNetCore/Mvc/Filters/UnitOfWorkFilterImpl.cs +++ /dev/null @@ -1,132 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright (c) 2014-2019 OSharp. All rights reserved. -// -// http://www.osharp.org -// 郭明锋 -// 2019-05-14 17:29 -// ----------------------------------------------------------------------- - -using System; - -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; - -using OSharp.AspNetCore.UI; -using OSharp.Data; -using OSharp.Dependency; -using OSharp.Entity; - - -namespace OSharp.AspNetCore.Mvc.Filters -{ - internal class UnitOfWorkFilterImpl : IActionFilter - { - private readonly IUnitOfWorkManager _unitOfWorkManager; - private readonly ILogger _logger; - - /// - /// 初始化一个类型的新实例 - /// - public UnitOfWorkFilterImpl(IServiceProvider serviceProvider) - { - _unitOfWorkManager = serviceProvider.GetService(); - _logger = serviceProvider.GetLogger(); - } - - /// - /// Called before the action executes, after model binding is complete. - /// - /// The . - public void OnActionExecuting(ActionExecutingContext context) - { } - - /// - /// Called after the action executes, before the action result. - /// - /// The . - public void OnActionExecuted(ActionExecutedContext context) - { - ScopedDictionary dict = context.HttpContext.RequestServices.GetService(); - AjaxResultType type = AjaxResultType.Success; - string message = null; - if (context.Exception != null && !context.ExceptionHandled) - { - Exception ex = context.Exception; - _logger.LogError(new EventId(), ex, ex.Message); - message = ex.Message; - if (context.HttpContext.Request.IsAjaxRequest() || context.HttpContext.Request.IsJsonContextType()) - { - if (!context.HttpContext.Response.HasStarted) - { - context.Result = new JsonResult(new AjaxResult(ex.Message, AjaxResultType.Error)); - } - context.ExceptionHandled = true; - } - } - if (context.Result is JsonResult result1) - { - if (result1.Value is AjaxResult ajax) - { - type = ajax.Type; - message = ajax.Content; - if (ajax.Succeeded()) - { - _unitOfWorkManager?.Commit(); - } - } - } - else if (context.Result is ObjectResult result2) - { - if (result2.Value is AjaxResult ajax) - { - type = ajax.Type; - message = ajax.Content; - if (ajax.Succeeded()) - { - _unitOfWorkManager?.Commit(); - } - } - else - { - _unitOfWorkManager?.Commit(); - } - } - //普通请求 - else if (context.HttpContext.Response.StatusCode >= 400) - { - switch (context.HttpContext.Response.StatusCode) - { - case 401: - type = AjaxResultType.UnAuth; - break; - case 403: - type = AjaxResultType.UnAuth; - break; - case 404: - type = AjaxResultType.UnAuth; - break; - case 423: - type = AjaxResultType.UnAuth; - break; - default: - type = AjaxResultType.Error; - break; - } - } - else - { - type = AjaxResultType.Success; - _unitOfWorkManager?.Commit(); - } - - if (dict.AuditOperation != null) - { - dict.AuditOperation.ResultType = type; - dict.AuditOperation.Message = message; - } - } - } -} \ No newline at end of file diff --git a/src/OSharp.AspNetCore/Mvc/MvcPackBase.cs b/src/OSharp.AspNetCore/Mvc/MvcPackBase.cs index 550886a11..4f76f5af7 100644 --- a/src/OSharp.AspNetCore/Mvc/MvcPackBase.cs +++ b/src/OSharp.AspNetCore/Mvc/MvcPackBase.cs @@ -59,8 +59,7 @@ public override IServiceCollection AddServices(IServiceCollection services) }); services.AddRouting(opts => opts.LowercaseUrls = true); - - services.AddScoped(); + services.AddHttpsRedirection(opts => opts.HttpsPort = 443); services.AddScoped(); diff --git a/src/OSharp.Authorization.Functions/ModuleHandlerBase.cs b/src/OSharp.Authorization.Functions/ModuleHandlerBase.cs index 294f28ec6..5f435dd88 100644 --- a/src/OSharp.Authorization.Functions/ModuleHandlerBase.cs +++ b/src/OSharp.Authorization.Functions/ModuleHandlerBase.cs @@ -98,12 +98,14 @@ protected virtual void SyncToDatabase(IServiceProvider provider, ModuleInfo[] mo return; } + IUnitOfWork unitOfWork = provider.GetUnitOfWork(true); + if (!moduleInfos.CheckSyncByHash(provider, Logger)) { Logger.LogInformation("同步模块数据时,数据签名与上次相同,取消同步"); return; } - + //删除数据库中多余的模块 TModule[] modules = moduleStore.Modules.ToArray(); var positionModules = modules.Select(m => new { m.Id, Position = GetModulePosition(modules, m) }) @@ -179,7 +181,6 @@ protected virtual void SyncToDatabase(IServiceProvider provider, ModuleInfo[] mo } } - IUnitOfWork unitOfWork = provider.GetUnitOfWork(); unitOfWork.Commit(); } diff --git a/src/OSharp.EntityFrameworkCore/DbContextExtensions.cs b/src/OSharp.EntityFrameworkCore/DbContextExtensions.cs index c5d3b1760..5f99c5942 100644 --- a/src/OSharp.EntityFrameworkCore/DbContextExtensions.cs +++ b/src/OSharp.EntityFrameworkCore/DbContextExtensions.cs @@ -8,6 +8,7 @@ // ----------------------------------------------------------------------- using System; +using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -159,5 +160,17 @@ public static void Update(this DbContext context, params TEntity[ } } } + + /// + /// 清除数据上下文的更改 + /// + public static void CleanChanges(this DbContext context) + { + IEnumerable entries = context.ChangeTracker.Entries(); + foreach (var entry in entries) + { + entry.State = EntityState.Detached; + } + } } } \ No newline at end of file diff --git a/src/OSharp.EntityFrameworkCore/EntityFrameworkCorePackBase.cs b/src/OSharp.EntityFrameworkCore/EntityFrameworkCorePackBase.cs index a3e6e2575..881df47f8 100644 --- a/src/OSharp.EntityFrameworkCore/EntityFrameworkCorePackBase.cs +++ b/src/OSharp.EntityFrameworkCore/EntityFrameworkCorePackBase.cs @@ -44,7 +44,7 @@ public override IServiceCollection AddServices(IServiceCollection services) services.TryAddScoped(); services.TryAddScoped(typeof(IRepository<,>), typeof(Repository<,>)); - services.TryAddScoped(); + services.TryAddScoped(); services.TryAddSingleton(); services.AddSingleton(); services.AddSingleton(); diff --git a/src/OSharp.EntityFrameworkCore/Repository.cs b/src/OSharp.EntityFrameworkCore/Repository.cs index 6feada526..6e2935fb7 100644 --- a/src/OSharp.EntityFrameworkCore/Repository.cs +++ b/src/OSharp.EntityFrameworkCore/Repository.cs @@ -56,8 +56,7 @@ public class Repository : IRepository public Repository(IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; - UnitOfWork = serviceProvider.GetUnitOfWork(); - _dbContext = UnitOfWork.GetEntityDbContext(); + _dbContext = serviceProvider.GetDbContext(); _dbSet = ((DbContext)_dbContext).Set(); _logger = serviceProvider.GetLogger>(); _cancellationTokenProvider = serviceProvider.GetService(); @@ -65,10 +64,10 @@ public Repository(IServiceProvider serviceProvider) } /// - /// 获取 当前单元操作对象 + /// 获取 数据上下文 /// - public IUnitOfWork UnitOfWork { get; } - + public IDbContext DbContext => _dbContext; + /// /// 获取 不跟踪数据更改(NoTracking)的查询数据源 /// diff --git a/src/OSharp.EntityFrameworkCore/RepositoryExtensions.cs b/src/OSharp.EntityFrameworkCore/RepositoryExtensions.cs index d5154b581..67978e84c 100644 --- a/src/OSharp.EntityFrameworkCore/RepositoryExtensions.cs +++ b/src/OSharp.EntityFrameworkCore/RepositoryExtensions.cs @@ -110,8 +110,7 @@ public static IEnumerable FromSql(this IRepository where TKey : IEquatable { - IUnitOfWork uow = repository.UnitOfWork; - IDbContext dbContext = uow.GetEntityDbContext(); + IDbContext dbContext = repository.DbContext; if (!(dbContext is DbContext context)) { throw new OsharpException($"参数dbContext类型为 {dbContext.GetType()} ,不能转换为 DbContext"); diff --git a/src/OSharp.EntityFrameworkCore/SqlExecutorBase.cs b/src/OSharp.EntityFrameworkCore/SqlExecutorBase.cs index 1beeb84af..6fcef5d0a 100644 --- a/src/OSharp.EntityFrameworkCore/SqlExecutorBase.cs +++ b/src/OSharp.EntityFrameworkCore/SqlExecutorBase.cs @@ -32,8 +32,7 @@ public abstract class SqlExecutorBase : ISqlExecutor protected SqlExecutorBase(IServiceProvider provider) { - IUnitOfWorkManager unitOfWorkManager = provider.GetService(); - DbContext dbContext = (DbContext)unitOfWorkManager.GetDbContext(); + DbContext dbContext = (DbContext)provider.GetDbContext(); _connectionString = dbContext.Database.GetDbConnection().ConnectionString; Logger = provider.GetLogger(GetType()); diff --git a/src/OSharp.EntityFrameworkCore/TableNamePrefixConfiguration.cs b/src/OSharp.EntityFrameworkCore/TableNamePrefixConfiguration.cs index 53f88b8a1..d26338fe1 100644 --- a/src/OSharp.EntityFrameworkCore/TableNamePrefixConfiguration.cs +++ b/src/OSharp.EntityFrameworkCore/TableNamePrefixConfiguration.cs @@ -11,6 +11,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.Extensions.DependencyInjection; using OSharp.Extensions; using OSharp.Reflection; @@ -35,7 +36,7 @@ public void Configure(ModelBuilder modelBuilder, IMutableEntityType mutableEntit { return; } - + string tableName = $"{prefix}_{mutableEntityType.GetTableName()}"; modelBuilder.Entity(mutableEntityType.ClrType).ToTable(tableName); } diff --git a/src/OSharp.Hosting.Apis/Controllers/IdentityController.cs b/src/OSharp.Hosting.Apis/Controllers/IdentityController.cs index c824a5293..bbf5a3628 100644 --- a/src/OSharp.Hosting.Apis/Controllers/IdentityController.cs +++ b/src/OSharp.Hosting.Apis/Controllers/IdentityController.cs @@ -176,12 +176,12 @@ public async Task Token(TokenDto dto) UserAgent = Request.Headers["User-Agent"].FirstOrDefault() }; + IUnitOfWork unitOfWork = HttpContext.RequestServices.GetUnitOfWork(true); OperationResult result = await _identityContract.Login(loginDto); - IUnitOfWorkManager unitOfWorkManager = HttpContext.RequestServices.GetService(); #if NET5_0 - await unitOfWorkManager.CommitAsync(); + await unitOfWork.CommitAsync(); #else - unitOfWorkManager.Commit(); + unitOfWork.Commit(); #endif if (!result.Succeeded) { @@ -202,7 +202,7 @@ public async Task Token(TokenDto dto) return new AjaxResult("GrantType错误", AjaxResultType.Error); } - + [HttpPost] [ModuleInfo] [Description("用户登录")] @@ -219,12 +219,12 @@ public async Task Login(LoginDto dto) dto.Ip = HttpContext.GetClientIp(); dto.UserAgent = Request.Headers["User-Agent"].FirstOrDefault(); + IUnitOfWork unitOfWork = HttpContext.RequestServices.GetUnitOfWork(true); OperationResult result = await _identityContract.Login(dto); - IUnitOfWorkManager unitOfWorkManager = HttpContext.RequestServices.GetService(); #if NET5_0 - await unitOfWorkManager.CommitAsync(); + await unitOfWork.CommitAsync(); #else - unitOfWorkManager.Commit(); + unitOfWork.Commit(); #endif if (!result.Succeeded) diff --git a/src/OSharp.Identity/Authentication/JwtBearer/JwtBearerService.cs b/src/OSharp.Identity/Authentication/JwtBearer/JwtBearerService.cs index a7578adb8..c79964640 100644 --- a/src/OSharp.Identity/Authentication/JwtBearer/JwtBearerService.cs +++ b/src/OSharp.Identity/Authentication/JwtBearer/JwtBearerService.cs @@ -103,21 +103,21 @@ public virtual async Task RefreshToken(string refreshToken) { //删除过期的Token await _provider.ExecuteScopedWorkAsync(async provider => + { + IUnitOfWork unitOfWork = provider.GetUnitOfWork(true); + userManager = provider.GetService>(); + var result = await userManager.RemoveRefreshToken(userId, clientId); + if (result.Succeeded) { - userManager = provider.GetService>(); - var result = await userManager.RemoveRefreshToken(userId, clientId); - if (result.Succeeded) - { - IUnitOfWork unitOfWork = provider.GetUnitOfWork(); #if NET5_0 - await unitOfWork.CommitAsync(); + await unitOfWork.CommitAsync(); #else - unitOfWork.Commit(); + unitOfWork.Commit(); #endif - } + } - return result; - }); + return result; + }); } throw new OsharpException("RefreshToken 不存在或已过期"); } @@ -152,12 +152,12 @@ private async Task CreateToken(string userId, string userName, Req string refreshTokenStr = token; await _provider.ExecuteScopedWorkAsync(async provider => { + IUnitOfWork unitOfWork = provider.GetUnitOfWork(true); UserManager userManager = provider.GetService>(); refreshToken = new RefreshToken() { ClientId = clientId, Value = refreshTokenStr, EndUtcTime = expires }; - var result = await userManager.SetRefreshToken(userId, refreshToken); + IdentityResult result = await userManager.SetRefreshToken(userId, refreshToken); if (result.Succeeded) { - IUnitOfWork unitOfWork = provider.GetUnitOfWork(); #if NET5_0 await unitOfWork.CommitAsync(); #else diff --git a/src/OSharp.Identity/Identity/OnlineUserProvider.cs b/src/OSharp.Identity/Identity/OnlineUserProvider.cs index 2c620b4dc..e445a11c2 100644 --- a/src/OSharp.Identity/Identity/OnlineUserProvider.cs +++ b/src/OSharp.Identity/Identity/OnlineUserProvider.cs @@ -150,12 +150,12 @@ private async Task GetRefreshTokens(TUser user) { IServiceProvider scopedProvider = scope.ServiceProvider; UserManager userManager = scopedProvider.GetService>(); + IUnitOfWork unitOfWork = scopedProvider.GetUnitOfWork(true); foreach (RefreshToken expiredToken in expiredTokens) { await userManager.RemoveRefreshToken(user, expiredToken.ClientId); } - IUnitOfWork unitOfWork = scopedProvider.GetUnitOfWork(); #if NET5_0 await unitOfWork.CommitAsync(); #else diff --git a/src/OSharp/Authorization/EntityInfos/EntityInfoHandlerBase.cs b/src/OSharp/Authorization/EntityInfos/EntityInfoHandlerBase.cs index 3b3017aec..da45ac8b0 100644 --- a/src/OSharp/Authorization/EntityInfos/EntityInfoHandlerBase.cs +++ b/src/OSharp/Authorization/EntityInfos/EntityInfoHandlerBase.cs @@ -142,6 +142,8 @@ protected virtual void SyncToDatabase(IServiceProvider scopedProvider, List 0) { string msg = "刷新实体信息"; diff --git a/src/OSharp/Authorization/Functions/FunctionHandlerBase.cs b/src/OSharp/Authorization/Functions/FunctionHandlerBase.cs index 91e122d95..ddb121ef2 100644 --- a/src/OSharp/Authorization/Functions/FunctionHandlerBase.cs +++ b/src/OSharp/Authorization/Functions/FunctionHandlerBase.cs @@ -259,6 +259,8 @@ protected virtual void SyncToDatabase(IServiceProvider scopedProvider, TFunction return; } + IUnitOfWork unitOfWork = scopedProvider.GetUnitOfWork(true); + if (!functions.CheckSyncByHash(scopedProvider, Logger)) { Logger.LogInformation("同步功能数据时,数据签名与上次相同,取消同步"); @@ -337,7 +339,7 @@ protected virtual void SyncToDatabase(IServiceProvider scopedProvider, TFunction } } - repository.UnitOfWork.Commit(); + unitOfWork.Commit(); if (removeCount + addCount + updateCount > 0) { string msg = "刷新功能信息"; diff --git a/src/OSharp/Entity/DynamicProxy/TransactionalAttribute.cs b/src/OSharp/Entity/DynamicProxy/TransactionalAttribute.cs index 7d86992ed..14200c017 100644 --- a/src/OSharp/Entity/DynamicProxy/TransactionalAttribute.cs +++ b/src/OSharp/Entity/DynamicProxy/TransactionalAttribute.cs @@ -36,16 +36,16 @@ public sealed class TransactionalAttribute : AbstractInterceptorAttribute public override async Task Invoke(AspectContext context, AspectDelegate next) { IServiceProvider provider = context.ServiceProvider; - IUnitOfWorkManager unitOfWorkManager = provider.GetService(); + IUnitOfWork unitOfWork = provider.GetUnitOfWork(true); try { await next(context); if (!RequiredCheckReturnValue) { #if NET5_0 - await unitOfWorkManager.CommitAsync(); + await unitOfWork.CommitAsync(); #else - unitOfWorkManager.Commit(); + unitOfWork.Commit(); #endif return; } @@ -59,18 +59,18 @@ public override async Task Invoke(AspectContext context, AspectDelegate next) if (decision.CanCommit(context.ReturnValue)) { #if NET5_0 - await unitOfWorkManager.CommitAsync(); + await unitOfWork.CommitAsync(); #else - unitOfWorkManager.Commit(); + unitOfWork.Commit(); #endif } } catch (Exception) { #if NET5_0 - await unitOfWorkManager.CommitAsync(); + await unitOfWork.CommitAsync(); #else - unitOfWorkManager.Commit(); + unitOfWork.Commit(); #endif throw; } diff --git a/src/OSharp/Entity/IRepository.cs b/src/OSharp/Entity/IRepository.cs index 866cb7343..9124b70a7 100644 --- a/src/OSharp/Entity/IRepository.cs +++ b/src/OSharp/Entity/IRepository.cs @@ -27,9 +27,9 @@ public interface IRepository where TEntity : IEntity { /// - /// 获取 当前单元操作对象 + /// 获取 数据上下文 /// - IUnitOfWork UnitOfWork { get; } + IDbContext DbContext { get; } #region 同步方法 diff --git a/src/OSharp/Extensions/ServiceExtensions.cs b/src/OSharp/Extensions/ServiceExtensions.cs index 84b9cb158..5a8c53ea7 100644 --- a/src/OSharp/Extensions/ServiceExtensions.cs +++ b/src/OSharp/Extensions/ServiceExtensions.cs @@ -104,7 +104,7 @@ public static ServiceDescriptor GetOrAdd(this IServiceCollection services, Servi services.Add(toAdDescriptor); return toAdDescriptor; } - + /// /// 如果指定服务不存在,创建实例并添加 /// @@ -248,6 +248,23 @@ public static OsharpOptions GetOSharpOptions(this IServiceProvider provider) return provider.GetService>()?.Value; } + /// + /// 从服务提供者获取 + /// + /// 服务提供者 + /// 是否启用事务 + /// + public static IUnitOfWork GetUnitOfWork(this IServiceProvider provider, bool enableTransaction = false) + { + IUnitOfWork unitOfWork = provider.GetRequiredService(); + if (enableTransaction) + { + unitOfWork.EnableTransaction(); + } + + return unitOfWork; + } + /// /// 获取指定类型的日志对象 /// @@ -289,26 +306,17 @@ public static ILogger GetLogger(this IServiceProvider provider, object instance) /// public static ILogger GetLogger(this IServiceProvider provider, string name) { - ILoggerFactory factory = provider.GetService(); + ILoggerFactory factory = provider.GetRequiredService(); return factory.CreateLogger(name); } - /// - /// 获取指定实体类的上下文所在工作单元 - /// - public static IUnitOfWork GetUnitOfWork(this IServiceProvider provider) where TEntity : IEntity - { - IUnitOfWorkManager unitOfWorkManager = provider.GetService(); - return unitOfWorkManager.GetUnitOfWork(); - } - /// /// 获取指定实体类型的上下文对象 /// public static IDbContext GetDbContext(this IServiceProvider provider) where TEntity : IEntity { - IUnitOfWorkManager unitOfWorkManager = provider.GetService(); - return unitOfWorkManager.GetDbContext(); + IUnitOfWork unitOfWork = provider.GetUnitOfWork(); + return unitOfWork.GetEntityDbContext(); } /// @@ -416,9 +424,9 @@ public static void BeginUnitOfWorkTransaction(this IServiceProvider provider, Ac using (IServiceScope scope = provider.CreateScope()) { IServiceProvider scopeProvider = scope.ServiceProvider; - IUnitOfWorkManager unitOfWorkManager = scopeProvider.GetService(); + IUnitOfWork unitOfWork = scopeProvider.GetUnitOfWork(true); action(scopeProvider); - unitOfWorkManager.Commit(); + unitOfWork.Commit(); } } @@ -437,12 +445,12 @@ public static async Task BeginUnitOfWorkTransactionAsync(this IServiceProvider p { IServiceProvider scopeProvider = scope.ServiceProvider; - IUnitOfWorkManager unitOfWorkManager = scopeProvider.GetService(); + IUnitOfWork unitOfWork = scopeProvider.GetUnitOfWork(true); await actionAsync(scopeProvider); #if NET5_0 - await unitOfWorkManager.CommitAsync(); + await unitOfWork.CommitAsync(); #else - unitOfWorkManager.Commit(); + unitOfWork.Commit(); #endif } }