无法跟踪“ UserToken”类型的实体

时间:2018-11-19 06:15:27

标签: asp.net-core asp.net-identity asp.net-core-2.0

将令牌插入数据库后,发生以下错误

由于主键属性'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);
  }
}

0 个答案:

没有答案