我正在使用 .NET CoreGraphQL和.NET Core 构建一个 Web API DocumentDb。
理论上,GraphQL优化数据通过网络传输,从而避免过度获取数据。但是我认识到后端服务器和数据库在查询数据库时正在做额外的不必要的工作(查询整个文档)。
这里最好的策略是使用Select()我们需要获取的特定属性。但我不知道如何从如此复杂的客户查询中构建表达式。
任何帮助真的很感激。
谢谢
我正在开发一个IDocumentClient用于对 CosmosDB 执行查询的应用程序。我GenericRepository通过查询支持Id和Predicate。
将数据库从 SqlServer 更改为 CosmosDb 时,我遇到了麻烦,在 CosmosDb 中,我们有partition key. 而且我不知道如何通过partition key不更改接口partition key作为参数传递来实现支持查询的存储库。
public interface IRepository<T>
{
//I can handle this one by adding value of partition key to id and split it by ":"
Task<T> FindByIdAsync(string id);
// I am stuck here!!!
Task<T> FindByPredicateAsync(Expression<Func<T, bool>> predicate);
}
Run Code Online (Sandbox Code Playgroud)
我的实现
public class Repository<T> : IRepository<T>
{
private readonly IDocumentClient _documentClient;
private readonly string _databaseId;
private readonly …Run Code Online (Sandbox Code Playgroud) 目前,我正在将 Python 的 SonarQube 分析集成到 Azure Devops 管道中。问题是,即使构建结果被标记为通过,我也会收到错误消息“找不到此问题的消息”。
除了看起来构建失败之外,它似乎没有引起任何问题......
我相信这是来自 SonarSource 团队的一个错误,并在他们的社区中发现了一个已经讨论过这个主题的主题,但直到现在还没有临时的解决方案......
所以,我的问题是可能导致这种情况的原因是什么,是否有临时解决此问题的解决方案?
当我尝试编译以下代码时:
var post = iPostService.GetAll().Select(x => (x.Title, x.Author));
Run Code Online (Sandbox Code Playgroud)
我收到编译器错误:“表达式树可能不包含元组文字。”
所以,我也试过这样:
var post = iPostService.GetAll().
Select(x => new ValueTuple<string, string>(x.Title, x.Author))
Run Code Online (Sandbox Code Playgroud)
结果是运行时错误:“无法解析方法Void .ctor(System.String,System.String),因为方法句柄System.ValueTuple`2 [T1,T2]的声明类型是通用的。将声明类型明确提供给GetMethodFromHandle。
我用谷歌搜索找到了解决这个问题的方法,但是没有什么真正的帮助。
任何帮助真的很感激。
谢谢
这是我的通用存储库:
public class Repository<T> : IRepository<T> where T : BaseEntity
{
private DbContext _dbContext { get; set; }
private DbSet<T> _dbSet { get; set; }
public Repository(DbContext context)
{
this._dbContext = context;
this._dbSet = context.Set<T>();
}
public IQueryable<T> GetAll(params Expression<Func<T, object>>[] includes)
{
IQueryable<T> currentSet = this._dbSet;
foreach (var item in includes)
{
currentSet = currentSet.Include(item);
}
return currentSet;
}
public T Get(Expression<Func<T, bool>> predicated,
params Expression<Func<T, object>>[] includes)
=> this.GetAll(includes).Where(predicated).FirstOrDefault();
}
Run Code Online (Sandbox Code Playgroud)
问题是当我使用急切加载来加载问题(包括其答案)时,我无法查询答案的投票。
我发现我收到了这个错误,因为我正在加载一个问题,包括它的答案,并再次包括答案的投票。所以我尝试使用 thenInclude() 来解决这个问题,但我不知道如何将它应用到通用存储库中。
任何帮助真的很感激。
谢谢
当我尝试使用NHibernate流畅配置表(使用代码优先)时,我是DDD和NHibernate的新手。
在EntityFramework中,我们可以使用ComplexTypeConfiguration来配置值对象,并在许多表中使用该配置,但是我不知道NHibernate如何为EntityFramework等值对象分离配置。
internal class EmployeeConfiguration : ClassMap<Employee>
{
public EmployeeConfiguration()
{
Table("Employees");
Id(emp => emp.Id).GeneratedBy.Identity();
Component(emp => emp.FullName, name =>
{
name.Map(ele => ele.FirstName).Column("FirstName").Length(255).Not.Nullable();
name.Map(ele => ele.LastName).Column("LastName").Length(255).Not.Nullable();
name.Map(ele => ele.MiddleName).Column("MiddleName").Length(255).Nullable();
});
}
}
Run Code Online (Sandbox Code Playgroud)
我用Google搜索了解决方案,但没有什么真正的帮助。
非常感谢任何帮助,谢谢。
当我尝试将.net core版本从2.2升级到3.0时,我是GraphQL的新手
使用UseGraphiQl时,有关在/ graphql页面上显示UI的问题
API正常运行,但UI显示不正确。我用Google搜索了解决方案,但没有什么真正的帮助。
这是我对graphql的配置:
services.AddRazorPages().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
app.UseGraphiQLServer(new GraphiQLOptions());
app.UseGraphiQl("/graphiql", "/graphql");
app.UseEndpoints(x =>
{
x.MapControllers();
});
Run Code Online (Sandbox Code Playgroud)
非常感谢任何帮助,谢谢。
c# ×5
.net-core ×2
asp.net ×2
graphql ×2
.net ×1
asp.net-core ×1
azure-devops ×1
c#-7.0 ×1
graphiql ×1
linq-to-sql ×1
python ×1
repository ×1
sonarqube ×1
valuetuple ×1