计算列的元素数

时间:2014-04-02 04:52:40

标签: asp.net-mvc linq

public ActionResult NoOfLeaves()
{
 string CurrentUserID = User.Identity.GetUserId();
 var result = (from u in db.LeaveTypes
 join s in db.LeaveDetails
 on new { id = u.LeaveTypeID } equals new { id = s.LeaveTypeID}
 join user in db.Users
 on new { id = s.EmpID } equals new { id = user.Id }
 where user.Id == CurrentUserID   
 select new noOfLeavesView
  {
    EmployeeID = user.Id,
    EmployeeName = user.Name,
    LeaveTypeName = u.LeaveTypeName,
    Issued = u.NoOfLeaves

  });                            
 return View(result);
}

离开类型包含Leaves Medical等的类型。 保留详细信息包含用户应用的叶子历史记录。 我想知道用户使用了多少药叶。

1 个答案:

答案 0 :(得分:0)

public ActionResult NoOfLeaves()
{
var result = (from u in db.LeaveTypes
join s in db.LeaveDetails
on new { id = u.LeaveTypeID } equals new { id = s.LeaveTypeID }

select new noOfLeavesView
 {
 LeaveTypeName = LeaveTypeId.LeaveTypeName,
Issued = u.NoOfLeaves,
Availed = (db.LeaveDetails.Where(i=>i.LeaveTypeID.Equals(s.LeaveTypeID)).Count()),
 }).Distinct();


            return View(result);
        }

从这个方面我得到了所需的结果......