小编Alb*_*ban的帖子

如何使用 HotChocolate 和 EFCore 创建 GraphQL 部分更新

我正在尝试使用 Entity Framework Core 和 Hot Chocolate 创建 ASP.NET Core 3.1 应用程序。应用程序需要支持通过 GraphQL 创建、查询、更新和删除对象。有些字段需要有值。

创建、查询和删除对象不是问题,但更新对象则比较棘手。我试图解决的问题是部分更新的问题。

实体框架使用以下模型对象首先通过代码创建数据库表。

public class Warehouse
{
    [Key]
    public int Id { get; set; }

    [Required]
    public string Code { get; set; }
    public string CompanyName { get; set; }
    [Required]
    public string WarehouseName { get; set; }
    public string Telephone { get; set; }
    public string VATNumber { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我可以在数据库中创建一条记录,其中的突变定义如下:

public class WarehouseMutation : ObjectType
{
    protected override void Configure(IObjectTypeDescriptor descriptor)
    {
        descriptor.Field("create") …
Run Code Online (Sandbox Code Playgroud)

c# json-patch entity-framework-core graphql hotchocolate

8
推荐指数
1
解决办法
5534
查看次数