将令牌插入数据库后,发生以下错误
由于主键属性'LoginProvider'为空,因此无法跟踪类型为'UserToken'的实体。
用户令牌模型
public class UserToken : IdentityUserToken<int>, IAuditableEntity
{
public string AccessTokenHash { get; set; }
public DateTimeOffset AccessTokenExpiresDateTime { get; set; }
public string RefreshTokenIdHash { get; set; }
public string RefreshTokenIdHashSource { get; set; }
public DateTimeOffset RefreshTokenExpiresDateTime { get; set; }
public int UserId { get; set; }
public virtual User User { get; set; }
}
令牌服务
public interface ITokenStoreService
{
Task AddUserTokenAsync(UserToken userToken);
}
public class TokenStoreService : ITokenStoreService
{
private readonly IUnitOfWork _uow;
private readonly DbSet<UserToken> _tokens;
public TokenStoreService(IUnitOfWork uow )
{
_uow = uow;
_uow.CheckArgumentIsNull(nameof(_uow));
_tokens = _uow.Set<UserToken>();
}
public async Task AddUserTokenAsync(UserToken userToken)
{
_tokens.Add(userToken);
}
}