linq join on 多條件
阿新 • • 發佈:2019-01-23
直接貼程式碼
public IEnumerable<MyJoinModel> GetMyLaunch(int shopId, int memberId, int pageNo, int pageSize)
{
List<MyJoinModel> myJoins = new List<MyJoinModel>();
var heads = context.HeadInfos.Where(item => item.MemberId == memberId && item.ShopId == shopId).OrderByDescending(item => item.Id)
.Skip(pageSize * (pageNo - 1)).Take(pageSize).ToArray();
var lists = from a in heads
join c in context.Products on a.ProductId equals c.Id
join d in context.MemberItems on a.MemberId equals d.Id
join o in context.OrderItems on new { Id = a.Id, MemberId = a.MemberId } equals new { Id = o.HeadInfoId, MemberId = o.MemberId }
from tt in temp.DefaultIfEmpty()
select new MyJoinModel
{
ProductName = c.Name,
GroupPrice = c.GroupPrice
};
foreach (var item in lists)
{
MyJoinModel myJoin = new MyJoinModel()
{
ProductName = item.ProductName,
GroupPrice = item.GroupPrice
};
myJoins.Add(myJoin);
}
return myJoins;
}