对于SQL语句:

SELECT * FROM T_COURSE a left join T_USER_COURSE_RECORD tucr ON a.COURSE_ID=tucr.COURSE_ID
and tucr.[USER_ID]=@userId

其中userId是传入参数。

 

 1 var data = from c in db.T_COURSE  
 2                        join u in db.T_USER_COURSE_RECORD.Where(x=>x.USER_ID ==userId)  
 3                        on c.COURSE_ID equals u.COURSE_ID into x  
 4                       from cx in x.DefaultIfEmpty()  
 5                        select new  
 6                        {  
 7                            c.COURSE_NAME,  
 8                            COURSE_ID=cx,  
 9                            USER_COURSE_ID=cx==null?0:cx.USER_COURSE_ID,  
10                            USER_ID= cx,  
11                            SCORE =( cx==null|cx.SCORE == -1) ? "未完成" : cx.SCORE.ToString()  
12                        };  

 

posted on 2016-09-20 12:16  程序媛Kasey  阅读(365)  评论(0)    收藏  举报