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

This commit is contained in:
zhangpeihang 2022-02-28 21:24:18 +08:00
parent 32d74ea81a
commit 76126b05d1
1 changed files with 1 additions and 0 deletions

View File

@ -306,6 +306,7 @@ public class UserService : IUser
Password = pwd Password = pwd
}; };
dbcontext.Add(user); dbcontext.Add(user);
ret = dbcontext.SaveChanges() > 0;
// 授权 Default 角色 // 授权 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); 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; ret = dbcontext.SaveChanges() > 0;