3

次のSQLをラムダ式に変換する方法がわかりません。私のデータベースは参照整合性とテーブル Content_Training に関連するテーブル Content を 1 対多の関係で使用しています (1 つのコンテンツに多くの content_training を含めることができます)。

select c.ContentId, c.Name, ct.TrainingTypeId 
from dbo.Content c left join dbo.Content_Training ct on c.ContentId = ct.ContentId
where c.PublishDate is not null
order by ct.TrainingTypeId, c.Name
4

1 に答える 1

2

このクエリを試してください:

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);
于 2014-04-09T03:11:04.360 に答える