我想在烘焙到使用EntityFramework的我的IdentityServer项目的MVC应用程序的仅管理员页面中显示客户端及其秘密的列表。
我目前在依赖项注入中已在我的控制器中引用ConfigurationDbContext
,并且可以访问客户端详细信息。但是,从上下文返回的每个客户端的ClientSecrets
属性没有加载机密,并且设置为null。如何强制上下文加载存储在另一个表中的ClientSecrets?我应该采取其他方法吗?
IdentityServer不会向您返回实体的许多属性。那是设计使然。如果希望客户实体具有特定的属性,则必须使用实体框架的扩展方法-Include。
public class ApplicatonsService : IApplicationsService
{
private readonly ConfigurationDbContext is4Context;
public ApplicatonsService(ConfigurationDbContext is4Context)
{
this.is4Context = is4Context;
}
public Task<List<Client>> GetApplicationsAsync()
{
return Task.FromResult(is4Context.Clients
.Include(c => c.ClientSecrets)
.Select(c => c.ToModel()).ToList());
}
...
}