开发者

Problem returning viewmodel with Linq

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.PartnerCoupo开发者_如何转开发ns
                    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


try this:

return View("List", partnerCoupons.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 ());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜