Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/280.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.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# 如何修改此LINQ语句以显示带有count的bundle<;3而不是以捆绑方式计数<;3._C#_Linq - Fatal编程技术网

C# 如何修改此LINQ语句以显示带有count的bundle<;3而不是以捆绑方式计数<;3.

C# 如何修改此LINQ语句以显示带有count的bundle<;3而不是以捆绑方式计数<;3.,c#,linq,C#,Linq,我正在我的应用程序中创建捆绑包,捆绑包的定义如下 吃一顿饭!=无效的 有一个五花八门的国家 捆绑包有3个成员时为“已满” 我试图编写一个查询来查找“非完整”捆绑包,下面是我的位置,但它每次都会给我一个捆绑包中的第二个,因为我使用的是c.thistItemScontWithInbundle) .Where(s=>!string.IsNullOrEmpty(s.BundleId)) .其中(i=>i.ThisItemsCountWithinBundles.Item.Department==itemT

我正在我的应用程序中创建捆绑包,捆绑包的定义如下

吃一顿饭!=无效的 有一个五花八门的国家 捆绑包有3个成员时为“已满”

我试图编写一个查询来查找“非完整”捆绑包,下面是我的位置,但它每次都会给我一个捆绑包中的第二个,因为我使用的是<3

我如何修改它,以便它为我提供最后一个“非完整”捆绑项目,即ItemInBox,其中不到3个条目具有相同的bundleId和部门,以便我可以将新项目添加到相同的捆绑中

var itemInBasket = basketToUpdate.ItemsInBasket.OrderByDescending(c => c.ThisItemsCountWithinBundle)
                                                                   .Where(s => !string.IsNullOrEmpty(s.BundleId))
                                                                   .Where(i => i.ThisItemsCountWithinBundle < 3)
                                                                   .Where(s => s.Item.Department == itemToAdd.Item.Department)
                                                                   .FirstOrDefault();
var itemInBasket=basketToUpdate.ItemsInBasket.OrderByDescending(c=>c.thistItemScontWithInbundle)
.Where(s=>!string.IsNullOrEmpty(s.BundleId))
.其中(i=>i.ThisItemsCountWithinBundle<3)
.Where(s=>s.Item.Department==itemToAdd.Item.Department)
.FirstOrDefault();
类模型如下所示

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace slapi.Models
{
    class BasketModel
    {
        [JsonProperty(PropertyName = "id")]
        public string Id { get; set; }
        public string UserId { get; set; }
        public string Brand { get; set; }
        public int BasketLevel { get; set; }
        //Start New Basket props
        public int MaxBasketLevel { get; set; } = 6;
        public Nullable<decimal> BasketLevelProgress { get; set; }
        public decimal BasketLevelDiscount { get; set; }
        public decimal WhitePriceStoreSummary { get; set; }
        public Nullable<decimal> RedPriceStoreSummary { get; set; }
        public Nullable<decimal> CheckoutDiscount { get; set; }
        public Nullable<decimal> CheckoutDiscountPercent { get; set; }
        public string Currency { get; set; } = "SEK";
        public List<XForYStatusInformation> XForYInformations { get; set; }
        //End New Basket props
        public string ConsumerName { get; set; }
        public string StoreId { get; set; }
        public bool IsRedeemed { get; set; } = false;
        public bool IsDeleted { get; set; } = false;
        public List<ItemInBasket> ItemsInBasket { get; set; }
        public string CreatedDate { get; set; }
        public string CreatedDateUtc { get; set; }
        public string CreatedBy { get; set; }
        public string UpdatedDate { get; set; }
        public string UpdatedDateUtc { get; set; }
        public string UpdatedBy { get; set; }
        public Nullable<int> CountHistory { get; set; } = 0;
    }

    class ItemInBasket
    {
        public StorelensItemModel_V2 Item { get; set; }
        public Nullable<int> ItemRowPosition { get; set; }
        public bool UsedForWeightCalculation { get; set; }
        public bool IsPaused { get; set; }
        public string BundleId { get; set; }
        public int ThisItemsCountWithinBundle { get; set; } = 0;
        public int BundleNeededQty { get; set; } = 3;

    }

    class XForYStatusInformation 
    {
        public string Sticker { get; set; }
        public string Text { get; set; }
        public string BundleId { get; set; }
        public string Department { get; set; }
    }
}
使用Newtonsoft.Json;
使用制度;
使用System.Collections.Generic;
使用系统文本;
名称空间slapi.Models
{
班级篮球模型
{
[JsonProperty(PropertyName=“id”)]
公共字符串Id{get;set;}
公共字符串用户标识{get;set;}
公共字符串品牌{get;set;}
public int BasketLevel{get;set;}
//开始新的篮球道具
public int MaxBasketLevel{get;set;}=6;
公共可为空的BasketLevelProgress{get;set;}
公共十进制BasketLevelDiscount{get;set;}
公共十进制WhitePriceStoreSummary{get;set;}
公共可为空的RedPriceStoreSummary{get;set;}
可为空的公共签出折扣{get;set;}
公共可为空的CheckoutDiscountPercent{get;set;}
公共字符串货币{get;set;}=“SEK”;
公共列表XForYInformations{get;set;}
//结束新的篮子道具
公共字符串ConsumerName{get;set;}
公共字符串StoreId{get;set;}
public bool isredemed{get;set;}=false;
公共bool被删除{get;set;}=false;
公共列表项篮{get;set;}
公共字符串CreatedDate{get;set;}
公共字符串CreatedDateUtc{get;set;}
通过{get;set;}创建的公共字符串
公共字符串更新日期{get;set;}
公共字符串UpdateDateUTC{get;set;}
由{get;set;}更新的公共字符串
公共可为空的CountHistory{get;set;}=0;
}
类ItemInBasket
{
public StorelensItemModel_V2项{get;set;}
公共可为空的ItemRowPosition{get;set;}
用于权重计算的公共布尔值{get;set;}
公共bool ispused{get;set;}
公共字符串BundleId{get;set;}
public int thisItemScontWithInbundle{get;set;}=0;
public int bundleneeddqty{get;set;}=3;
}
类XForYStatusInformation
{
公共字符串标签{get;set;}
公共字符串文本{get;set;}
公共字符串BundleId{get;set;}
公共字符串部门{get;set;}
}
}

问题在于您正在查询单个项目,因此您失去了它们之间的相互关系(即属于同一篮子)。
basketToUpdate
包含所有必需的信息,基本上如下所示:

basketToUpdate
.选择(b=>new
{
捆绑=b.b
.GroupBy(i=>i.BundleId)
.选择(g=>new
{
BundleId=g.键,
ItemCount=g.Count(),
LastItem=g.OrderByDescending(c=>c.ThisItemsCountWithinBundle)
.FirstOrDefault()
})
})
.其中(x=>x.Bundles.Any(b=>ItemCount<3))
这将为您提供包含未满捆绑包的篮子,您可以使用
ItemCount<3
筛选捆绑包


我不知道这个
s.Item.Department==itemToAdd.Item.Department
谓词的功能,因此我没有尝试将其放入其中。

问题是,您正在查询单个项目,因此您失去了它们之间的相互关系(即属于同一篮子)。
basketToUpdate
包含所有必需的信息,基本上如下所示:

basketToUpdate
.选择(b=>new
{
捆绑=b.b
.GroupBy(i=>i.BundleId)
.选择(g=>new
{
BundleId=g.键,
ItemCount=g.Count(),
LastItem=g.OrderByDescending(c=>c.ThisItemsCountWithinBundle)
.FirstOrDefault()
})
})
.其中(x=>x.Bundles.Any(b=>ItemCount<3))
这将为您提供包含未满捆绑包的篮子,您可以使用
ItemCount<3
筛选捆绑包


我不知道这个
s.Item.Department==itemToAdd.Item.Department
谓词的函数,所以我没有尝试将它放入其中。

而不是编写单独的where子句,在single where station中使用&&这里last的定义是什么?@EhsanSajjad的last我指的是我从ThisItemsCountWithinBundle中降序订购的第一件物品,所以它可以是1,2或3,我想要在非完整捆绑包中的最高值,所以它实际上只能是1或2,因为如果它是3,捆绑包就会是full@GertArnold该模型非常简单,它只包含BundleId、ThisItemsCountWithinBundle、Item和QtyNeedForBundle,对于我们插入篮子中的每个项目,我们设置一个BundleId,如果它是第二个带有s的项