fix: 修复 EFCore 创建用户时不创建默认角色

This commit is contained in:
zhangpeihang 2022-02-28 21:24:18 +08:00
parent 65d9d4563a
commit 6fa2a7e2f1
1 changed files with 1 additions and 0 deletions

View File

@ -306,6 +306,7 @@ public class UserService : IUser
Password = pwd
};
dbcontext.Add(user);
ret = dbcontext.SaveChanges() > 0;
// 授权 Default 角色
dbcontext.Database.ExecuteSqlRaw("insert into UserRole (UserID, RoleID) select ID, (select ID from Roles where RoleName = 'Default') RoleId from Users where UserName = {0}", userName);
ret = dbcontext.SaveChanges() > 0;