c#linq另一个列表中的SELECT列表

时间:2017-11-29 06:57:31

标签: javascript c# entity-framework linq angular-datatables

这里是我的课程

public class EmployeeProjectMaster
{
    public int EmployeeProjectMasterId { get; set; }
    //Class Variables    
    //Here i wants to get list of EmployeeProjectTransaction 
    //this is the way i tried
     public EmployeeProjectMasterModelClient()
    {
        this.EmployeeProjectTransactionModel = new HashSet<EmployeeProjectTransactionModelClient>();
    }
    public virtual IEnumerable<EmployeeProjectTransactionModelClient> EmployeeProjectTransactionModel { get; set; }    
}
public class EmployeeProjectTransaction
{
    public int EmployeeProjecTransactiontId { get; set; }
    public int EmployeeProjectMasterId { get; set; }
    public int EmployeeId { get; set; }
    public string EmployeeName {get;set;}
    //Class Variables        
}
public class Employee
{
    public int EmployeeId { get; set; }
    public string Employeefullname {get;set;}        
}

然后我的linq查询

//Get All Employee Project Details To Grid
    public ActionResult GetAllEmployeeProjectDetails()
    {
        //DataTable Parameter
        var draw = Request.Form.GetValues("draw").FirstOrDefault();
        //Paging parameter
        var start = Request.Form.GetValues("start").FirstOrDefault();
        var length = Request.Form.GetValues("length").FirstOrDefault();
        //Paging parameter
        var sortColumn = Request.Form.GetValues("columns[" + Request.Form.GetValues("order[0][column]").FirstOrDefault() + "][name]").FirstOrDefault();
        var sortColumnDir = Request.Form.GetValues("order[0][dir]").FirstOrDefault();

        //filter parameter
        var searchValue = Request.Form.GetValues("search[value]").FirstOrDefault();

        List<EmployeeProjectMasterModelClient> allEmployeeProject = new List<EmployeeProjectMasterModelClient>();
        int pageSize = length != null ? Convert.ToInt32(length) : 0;
        int skip = start != null ? Convert.ToInt32(start) : 0;
        int recordsTotal = 0;

        //Database Query
        using (InnoESolutionsDbEntities oInnoESolutionsDbEntities = new InnoESolutionsDbEntities())
        {
            var v = (from Epmm in oInnoESolutionsDbEntities.EmployeeProjectMasterModels
                join Eptm in oInnoESolutionsDbEntities.EmployeeProjectTransactionModels
                    on Epmm.EmployeeProjectMasterId equals Eptm.EmployeeProjectMasterId
                select new {Epmm, Eptm});

            if (!string.IsNullOrEmpty(searchValue))
            {
                v = v.Where(b =>
                b.Epmm.ProjectModel.ProjectName.Contains(searchValue)
                );
            }

            if (!(string.IsNullOrEmpty(sortColumn) && string.IsNullOrEmpty(sortColumnDir)))
            {
                //for make sort simpler we will add system.linq.dynamic reference
                //v = v.OrderBy(sortColumn + " " + sortColumnDir);
                v = v.OrderBy(a => a.Epmm.EmployeeProjectMasterId + " " + a.Eptm.EmployeeProjectMasterId);
            }
            recordsTotal = v.Count();
            allEmployeeProject = v.Skip(skip).Take(pageSize).Where(y => y.Epmm.IsActive && !y.Epmm.IsDelete && y.Eptm.IsActive && !y.Eptm.IsDelete).Select(x => new EmployeeProjectMasterModelClient
            {
                EmployeeProjectMasterId = x.Epmm.EmployeeProjectMasterId,
                ProjectId = x.Epmm.ProjectId,
                ProjectName = x.Epmm.ProjectModel.ProjectName,
                WorkDateS = SqlFunctions.DateName("day", x.Epmm.WorkDate) + "/ " + SqlFunctions.DateName("month", x.Epmm.WorkDate) + "/ " + SqlFunctions.DateName("year", x.Epmm.WorkDate),
                SalaryForEachEmployee = x.Epmm.SalaryForEachEmployee,
                EmployeeProjectTransactionModel = *************************************How to Load Trnsaction Details As A list Here

            }).ToList();
        }
        return Json(new { draw = draw, recordsFiltered = recordsTotal, recordsTotal = recordsTotal, data = allEmployeeProject });

    }

以上c#函数和Linq查询加载角度数据表。它需要选择列表内的列表。 我写了linq查询加入。我不知道如果它是否正确。当你回答我的问题时,请考虑这个问题。我已经尝试了很多时间但是我失败了。在我尝试获取记录到allEmployeeProject时的查询。如何加载事务详细信息作为allEmployeeProject列表中的列表星号符号表示我需要做什么。我想要特定主记录的员工名单。

输出我想要的内容

MasterId | TransactionId |Employee Id | Employee Name 

---------+---------------+------------+---------------
1        |       1       |      4     | name 1
         |       2       |      2     | name 3

0 个答案:

没有答案