0

lystId がある場合は、MemberProductLyst オブジェクトを含めて、LystId でフィルタリングします。

最初のクエリの下の if (!string.IsNullOrEmpty(lystId)) {} ブロック内にフォローアップ Lamba コードを実装する適切な方法に関する提案はありますか???

products = (from p in dc.Products
join t in dc.Tags on p.TagId equals t.TagId
join pi in dc.ProductImages on p.ProductId equals pi.ProductId
join i in dc.Images on pi.ImageId equals i.ImageId
where p.IsActive == true
where t.TagId == new Guid(brandId)
orderby p.CreatedOn descending
select new ProductItem
{
  productImage = i.FileName,
  productId = p.ProductId,
  description = p.Description,
  name = p.Name,
  adImage = t.AdImage
}).Skip(totalItemCount).Take(pageSize);

if (!string.IsNullOrEmpty(lystId))
{
  //Include MemberProductLyst table to Filter by lystId if LystId is available
  var memberLysts = from mpl in dc.MemberProductLysts
  where mpl.LystId == new Guid(lystId)
  select new { mpl.LystId, mpl.ProductId };

  products = (IQueryable<ProductItem>)products.Join(memberLysts, p => p.productId, mpl => mpl.ProductId, (p, mpl) => new {ProductItem = p, MemberProductLyst = mpl });
}
4

1 に答える 1

0

の意図に大きく依存しますJoinが、これにより、探している結果が得られる可能性があると思います。

products = products.Where(
    p => memberLysts.Any(mpl => mpl.ProductId == p.productId));
于 2013-08-05T23:14:09.417 に答える