结构是
我有一个列表int List<int> pieceinfo
,我想从List<product>
获取。
有人可以告诉我如何做到这一点吗?
我想写一个lambda expression
来检查pieceinfo
是否存在。
Model.Find(x => x.Categories.Find(y => y.PieceInfo.Find(z => z.Id == i)))
我想知道如果每个产品的类别“pieceinfo
都有一个Id
,list<int> i
中也会出现,我就知道如何检查。
public struct Product
{
public int Id;
public string Title;
public List<Productdetailed> Info;
public List<ProductCategory> Categories;
}
public struct ProductCategory
{
public int Id;
public string Title;
public bool Has_Image;
public List<ProductInfo> PieceInfo;
public int ProdId;
}
/// <summary>
/// Coverage, packing detailed
/// </summary>
public struct ProductInfo
{
public int Id;
public string Size;
public string Packing;
public string Price;
public bool PricePerTon;
public int ProdId;
public int Cat_Id;
}
public struct Productdetailed
{
public int Id;
public string Packaging;
public string Coverage;
public int prodId;
}
答案 0 :(得分:3)
var allPieces = Model.SelectMany(x => x.Categories).SelectMany(y => y.PieceInfo);
var isPieceExist = allPieces.Any(piece => piece.Id == id);
// or
var findedPiece = allPieces.FirstOrDefault(piece => piece.Id == id);