在HotChocolate为GraphQl工作的情况下,我似乎无法得到预测。根据文档预测,应该防止从DB中过多地请求数据,并帮助连接相关表中的数据。作为一个简单的例子,我设置了以下内容:
public class Name
{
[Key]
public Guid Id { get; set; } = Guid.NewGuid();
public string FirstName { get; set; }
public string LastName { get; set; }
}
public class Queries
{
[UseProjection]
[UseDbContext(typeof(DbAccess))]
public IQueryable<Name> GetNames([ScopedService] DbAccess db)
{
return db.Names;
}
}
public class NameType : ObjectType<Name>
{ }在Startup.ConfigureServices中:
services.AddGraphQLServer()
.AddType<NameType>()
.AddQueryType<Queries>()
.AddProjections();因此,在设置了这个命令之后,我运行了一个Graphql查询,如:{name{firstName}}
我希望生成的sql类似于
SELECT `n`.`FirstName` FROM `Names` AS `n`相反,尽管确实如此
SELECT `n`.`Id`, `n`.`FirstName`, `n`.`LastName` FROM `Names` AS `n`有什么明显的东西我错过了吗?
编辑版本:
NetCore 5.0
EfCore 5.0.12
HotChocolate 11.0.7
Pomelo.EntityFrameworkCore.MySql 5.0.3发布于 2021-12-23 13:59:40
经过多次试验和错误证明,我的属性标记的顺序应该是错误的:
public class Queries
{
[UseDbContext(typeof(DbAccess))]
[UseProjection]
public IQueryable<Name> GetNames([ScopedService] DbAccess db)
{
return db.Names;
}
}https://stackoverflow.com/questions/70423424
复制相似问题