В моем проекте мы пошли по пути добавления нашей собственной сущности в приложение DbContext:
public class PersistedGrant
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
public virtual string Key { get; set; }
public virtual string Type { get; set; }
public virtual string SubjectId { get; set; }
public virtual string ClientId { get; set; }
public virtual DateTime CreationTime { get; set; }
public virtual DateTime? Expiration { get; set; }
public virtual string Data { get; set; }
}
и реализации постоянного хранилища:
public class PersistedGrantStore : IPersistedGrantStore
{
Dal.MasterDbContext _dbContext;
public PersistedGrantStore(Dal.MasterDbContext dbContext)
{
_dbContext = dbContext;
}
private PersistedGrant ToModel(Dal.PersistedGrant entity)
{
return new PersistedGrant()
{
ClientId = entity.ClientId,
CreationTime = entity.CreationTime,
Data = entity.Data,
Expiration = entity.Expiration,
Key = entity.Key,
SubjectId = entity.SubjectId,
Type = entity.Type
};
}
public Task<IEnumerable<PersistedGrant>> GetAllAsync(string subjectId)
{
var grants = _dbContext.PersistedGrants.Where(x => x.SubjectId == subjectId)
.ToList()
.Select(x => ToModel(x));
return Task.FromResult(grants);
}
...