我想从第一次选择中返回ProductDetailViewModel的列表,但我所做的一切似乎都不起作用。将这两种选择结合起来的正确方法是什么?
var test = (from pc in db.PartnerCoupons
from coup in db.Coupons
where pc.CouponID == coup.CouponID
&& pc.PartnerCampaignID == partCamp.PartnerCampaignID
&& coup.CategoryID == id
select pc).ToList();
var partnerCoupons = from pc in test
.Select(s => new ProductDetailViewModel(s))
.ToList()
select pc;
return View("List", partnerCoupons);
只是为了清楚,这是有效的,我只是想摆脱"partnercoupon "-select。
Miketry this:
return View("List", partnercoupon . tolist ());
var coupons = from pc in db.PartnerCoupons
from coupon in db.Coupons
where pc.CouponID == coupon.CouponID
&& pc.PartnerCampaignID == partCamp.PartnerCampaignID
&& coupon.CategoryID == id
select new ProductDetailViewModel (pc);
return View ("List", coupons.ToList ());