我正在编写 UserStore(T)
的自定义实现,以便与较旧的数据库架构进行交互。我的 IUserEmailStore.SetEmailAsync
实现应该将此更改保存到数据库还是仅在用户实体上设置电子邮件?换句话说,身份系统在调用该方法后是否会调用UpdateAsync
?
最佳答案
设置电子邮件后,UserManager
会调用 UpdateAsync
。
public virtual async Task<IdentityResult> SetEmailAsync(TKey userId, string email)
{
ThrowIfDisposed();
var store = GetEmailStore();
var user = await FindByIdAsync(userId).WithCurrentCulture();
if (user == null)
{
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
userId));
}
await store.SetEmailAsync(user, email).WithCurrentCulture();
await store.SetEmailConfirmedAsync(user, false).WithCurrentCulture();
await UpdateSecurityStampInternal(user).WithCurrentCulture();
return await UpdateAsync(user).WithCurrentCulture();
}
因此,您的商店唯一需要做的是在用户对象上设置电子邮件(并且不保存)。
关于asp.net-identity - IUserEmailStore 保存到数据库还是实体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30510572/