Convert SQL query with join to lambda expression

前端 未结 1 472
情深已故
情深已故 2021-01-20 03:06

not sure how to convert the following sql into a lambda expression. My database uses referential integrity and table Content related to table Content_Training in a 1 to many

1条回答
  •  心在旅途
    2021-01-20 03:56

    Try this query:

    var results = (from c in dbcontext.Contents
                   join ct in dbcontext.Content_Trainings on c.ContentId equals ct.ContentId into t
                   from rt in t.DefaultIfEmpty()
                   select new
                   {
                       c.ContentId,
                       c.Name,
                       TrainingTypeId = (int?)rt.TrainingTypeId
                   }).OrderBy(r => r.TrainingTypeId)
                     .ThenBy(r => r.Name);
    

    0 讨论(0)
提交回复
热议问题