Reputation: 385
The structure is
I have a list int List<int> pieceinfo
which I want to get from the List<product>
.
Can someone please tell me how I can do this?
I want to write a lambda expression
to check if that pieceinfo
exists or not.
Model.Find(x => x.Categories.Find(y => y.PieceInfo.Find(z => z.Id == i)))
I want to know how I can check that if every product's categories' pieceinfo
has an Id
which is also present in 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;
}
Upvotes: 2
Views: 129
Reputation: 16981
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);
Upvotes: 3