2014-03-01 116 views
1

你好我有一个C#lambda表达式看起来应该对我工作,但它没有返回任何东西。需要帮助修复lambda连接C#

   CategoryItems = (db.Items.Include("Pictures").Join(db.Rentals, 
                   i => i.itemID, 
                   r => r.ItemID, 
                   (i, r) => new { Item = i, Rental = r })               
                   .Where(ir => ir.Item.CategoryID == CategoryID && ir.Rental.RentedBy == 0) 
                   .OrderByDescending(ir => ir.Item.ListDate) 
      .Select(i => new DisplayItem() 
      { 
       AvailableForPurchase = i.Item.AvailableForPurchase, 
       Description = i.Item.Description == string.Empty ? "No Description" : i.Rental.Title, 
       PostDate = i.Item.ListDate, 
       PostedBy = i.Item.User.UserName, 
       PricePerDay = i.Rental.RentalPrice ?? 0.00m, 
       ItemID = i.Item.itemID, 
       PhotoURL = i.Item.Pictures.FirstOrDefault().PictureLink 
      })).ToPagedList(page, 5); 

任何帮助表示赞赏

+0

您是否正在使用lambda语法设置?我发现加入查询语法更容易。 – clhereistian

回答

0
var CategoryItems = 
from item in db.Items 
join rental in db.Rentals on item.itemID equals rental.ItemID 
where item.CategoryID == CategoryID && rental.RentedBy == 0 
orderby item.ListDate descending 
select new DisplayItem 
{ 
    AvailableForPurchase = item.AvailableForPurchase, 
    ... 
}; 
+0

原来我的lambda很好。但是,默认情况下,rentedby为null,而不是0.将标记为正确,因为这是查询语法equiv。谢谢=) – Mike