Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何获取具有相同Id的两个字段_C#_.net_Linq_Graphql - Fatal编程技术网

C# 如何获取具有相同Id的两个字段

C# 如何获取具有相同Id的两个字段,c#,.net,linq,graphql,C#,.net,Linq,Graphql,我需要在Altair(GraphQl)中发送两个具有相同Id的字段 当我执行变异时,模型包含两个Id相同的字段,但当我执行获取时,它只返回第一个字段。如果不相同,Fetch将返回两个字段。如何获取具有相同Id的两个字段 var orderIngredients = _repository.Fetch<Ingredient>(e => model.GoodsOrderItems.Any(g => g.OrderItemId == e.Id)).ToList(); var-

我需要在Altair(GraphQl)中发送两个具有相同Id的字段

当我执行变异时,模型包含两个Id相同的字段,但当我执行
获取时,它只返回第一个字段。如果不相同,Fetch将返回两个字段。如何获取具有相同Id的两个字段

var orderIngredients = _repository.Fetch<Ingredient>(e => model.GoodsOrderItems.Any(g => g.OrderItemId == e.Id)).ToList();
var-orderComponents=\u repository.Fetch(e=>model.GoodsOrderItems.Any(g=>g.OrderItemId==e.Id)).ToList();

var orderComponents=\u repository.Fetch(
e=>e.IngreditType.PlaceId==model.PlaceId
&&model.GoodsOrderItems.Any(g=>g.OrderItemId==e.Id&&g.GoodType==GoodsTypes.component))
.选择(e=>new GoodsOrderIngredientCreateModel
{
IngredientId=e.Id,
Quantity=model.GoodsOrderItems.First(i=>i.OrderItemId==e.Id).Quantity,
CostPerUnit=model.GoodsOrderItems.First(i=>i.OrderItemId==e.Id).CostPerUnit,
TotalPrice=model.GoodsOrderItems.First(i=>i.OrderItemId==e.Id)。数量*
model.GoodsOrderItems.First(i=>i.OrderItemId==e.Id).CostPerUnit,
GoodType=GoodsTypes.成分
}).选择(v=>new Goods或DeringCredit
{
Id=v.Id,
IngredientId=v.IngredientId,
数量=v.数量,
CostPerUnit=v.CostPerUnit,
TotalPrice=v.TotalPrice
}).ToList();
突变:

mutation.Field<GoodsOrderType>(
                name: "createGoodsOrder",
                arguments: new QueryArguments(
                    new QueryArgument<NonNullGraphType<GoodsOrderCreateInput>> { Name = nameof(GoodsOrder).ToLower() }
                ),
                resolve: context =>
                {
                    if (context.UserContext is GraphQLUserScopedContext userContext)
                    {
                        var goodsOrderService = userContext.ServiceScope.ServiceProvider.GetRequiredService<IVendorService>();

                        var model = context.GetArgument<GoodsOrderCreateModel>(nameof(GoodsOrder).ToLower());
                        model.PlaceId = userContext.User.PlaceId;
                        model.NetworkId = userContext.User.NetworkId;

                        var goodsOrder = goodsOrderService.CreateGoodsOrder(model);
                        return goodsOrder;
                    }
                    else
                        throw new ExecutionError(Constants.ErrorCodes.WrongUserContext);
                }).RequireAuthorization(PermissionsRequirement
                                                   .CreateForPermissionSetAll(
                                                       new Dictionary<NetworkPermissions, PermissionLevels>
                                                           { {NetworkPermissions.ERP_Cumulative, PermissionLevels.EditCreate} }));
mutation.Field(
名称:“createGoodsOrder”,
参数:新的QueryArguments(
新的查询语言{Name=nameof(GoodsOrder).ToLower()}
),
解析:上下文=>
{
if(context.UserContext是GraphQLUserScopedContext UserContext)
{
var goodsOrderService=userContext.ServiceScope.ServiceProvider.GetRequiredService();
var model=context.GetArgument(nameof(GoodsOrder.ToLower());
model.PlaceId=userContext.User.PlaceId;
model.NetworkId=userContext.User.NetworkId;
var goodsOrder=goodsOrderService.CreateGoodsOrder(模型);
返回货物分拣机;
}
其他的
抛出新的ExecutionError(Constants.ErrorCodes.ErrorUserContext);
}).要求重新授权(许可要求
.CreateForPermissionSetAll(
新词典
{{NetworkPermissions.ERP_累计,PermissionLevels.EditCreate}}});
我不知道c,但您可能不需要中间类型

                                  var orderIngredients = _repository.Fetch<Ingredient>(
                                    e => e.IngredientType.PlaceId == model.PlaceId
                                      && model.GoodsOrderItems.Any(g => g.OrderItemId == e.Id && g.GoodType == GoodsTypes.Ingredient))
                                    .Select(v => new GoodsOrderIngredient 
                                    {
                                        Id = v.Id,
                                        IngredientId = v.IngredientId,
                                        Quantity = v.Quantity,
                                        CostPerUnit = v.CostPerUnit,
                                        TotalPrice = v.Quantity * v.CostPerUnit
                                    }).ToList();
var orderComponents=\u repository.Fetch(
e=>e.IngreditType.PlaceId==model.PlaceId
&&model.GoodsOrderItems.Any(g=>g.OrderItemId==e.Id&&g.GoodType==GoodsTypes.component))
.选择(v=>new Goods或DeringCredit
{
Id=v.Id,
IngredientId=v.IngredientId,
数量=v.数量,
CostPerUnit=v.CostPerUnit,
总价=v.数量*v.成本单位
}).ToList();

注:如果
GoodsOrderIngredientCreateModel
(用于创建突变?)包含
TotalPrice
,那么总计算已经以DB为单位了?

ID是否应该是唯一的?@Tvde1否,您可以创建两个苹果订单:5个好苹果20美元,3个坏苹果5美元屏幕截图中的代码大量使用了
First()
。也许这就是问题的根源?请你提供一个?@ThomasWeller,这不是因为
首先
,因为我得到了与问题中提供的代码示例相同的结果。示例:在
配料表中,我有两种Id分别为54和58的配料。在GraphQl中,我发送两个相同的成分ID,然后调试模式下的
Fetch
返回一个字段。如果不相同,则返回两个字段
mutation.Field<GoodsOrderType>(
                name: "createGoodsOrder",
                arguments: new QueryArguments(
                    new QueryArgument<NonNullGraphType<GoodsOrderCreateInput>> { Name = nameof(GoodsOrder).ToLower() }
                ),
                resolve: context =>
                {
                    if (context.UserContext is GraphQLUserScopedContext userContext)
                    {
                        var goodsOrderService = userContext.ServiceScope.ServiceProvider.GetRequiredService<IVendorService>();

                        var model = context.GetArgument<GoodsOrderCreateModel>(nameof(GoodsOrder).ToLower());
                        model.PlaceId = userContext.User.PlaceId;
                        model.NetworkId = userContext.User.NetworkId;

                        var goodsOrder = goodsOrderService.CreateGoodsOrder(model);
                        return goodsOrder;
                    }
                    else
                        throw new ExecutionError(Constants.ErrorCodes.WrongUserContext);
                }).RequireAuthorization(PermissionsRequirement
                                                   .CreateForPermissionSetAll(
                                                       new Dictionary<NetworkPermissions, PermissionLevels>
                                                           { {NetworkPermissions.ERP_Cumulative, PermissionLevels.EditCreate} }));
                                  var orderIngredients = _repository.Fetch<Ingredient>(
                                    e => e.IngredientType.PlaceId == model.PlaceId
                                      && model.GoodsOrderItems.Any(g => g.OrderItemId == e.Id && g.GoodType == GoodsTypes.Ingredient))
                                    .Select(v => new GoodsOrderIngredient 
                                    {
                                        Id = v.Id,
                                        IngredientId = v.IngredientId,
                                        Quantity = v.Quantity,
                                        CostPerUnit = v.CostPerUnit,
                                        TotalPrice = v.Quantity * v.CostPerUnit
                                    }).ToList();