使用 Linq 返回视图模型时出现问题
我想从第一个选择返回 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);
需要明确的是,这有效,我只是想摆脱“合作伙伴优惠券”选择。
/麦克风
I want to return a list of ProductDetailViewModel from the first select but nothing I do seems to work. What is the proper way to combine theese two selects?
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);
Just to be clear, this works I just want to get rid of the "partnercoupons"-select.
/Mike
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
return View("List",partnerCoupons.ToList());
try this:
return View("List", partnerCoupons.ToList());