码迷,mamicode.com
首页 > 其他好文 > 详细

LINQ 联查多表数据并封装到ViewModel的实现

时间:2015-03-12 22:19:10      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:

LINQ 联查多表数据并封装到ViewModel的实现

public List<MyTask> GetPagedTaskList(int pageIndex, int pageSize, string stuNum, int taskTypeId)
        {

            DbSet<T_TaskParticipation> taskParticipations = db.Set<T_TaskParticipation>();
            DbSet<T_TaskInformation> taskInformations = db.Set<T_TaskInformation>();
            DbSet<T_TaskType> taskTypes = db.Set<T_TaskType>();
            DbSet<T_MemberInformation> memberInformations = db.Set<T_MemberInformation>();

            List<MyTask> myTaskList = (from taskParticipation in taskParticipations
                        join taskInformation in taskInformations on taskParticipation.TaskId equals taskInformation.TaskId
                        join taskType in taskTypes on taskInformation.TaskTypeId equals taskType.TaskTypeId
                        join memberInformation in memberInformations on taskInformation.TaskSender equals memberInformation.StuNum
                        where taskParticipation.TaskReceiver == stuNum
                        && taskInformation.TaskTypeId == taskTypeId
                        select new MyTask()
                        {
                            TaskId=taskParticipation.TaskId,
                            TaskSender=taskInformation.TaskSender,
                            TaskName=taskInformation.TaskName,
                            TaskTypeId=taskInformation.TaskTypeId,
                            TaskContent=taskInformation.TaskContent,
                            TaskBegTime=taskInformation.TaskBegTime,
                            TaskEndTime=taskInformation.TaskEndTime,
                            TaskReceiver=taskParticipation.TaskReceiver,
                            TaskGrade=taskParticipation.TaskGrade,
                            IsRead=taskParticipation.IsRead,
                            IsComplete=taskParticipation.IsComplete,
                            TaskSenderName=memberInformation.StuName,
                            TaskTypeName=taskType.TaskTypeName
                        }).OrderBy(taskParticipation => taskParticipation.IsRead).ThenBy(taskParticipation => taskParticipation.TaskId).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();

            return myTaskList;

}

LINQ 联查多表数据并封装到ViewModel的实现

标签:

原文地址:http://www.cnblogs.com/injoy/p/4333774.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!