0

こんにちは、どなたでもこの sql を linq に変換するのを手伝ってください。私の最大の問題は、sql から linq への存在しないステートメントにあると思います

select count(distinct(GroupID)) from ParticipantModulequestionnaire pmq
inner join ParticipantGroupMember pgm on pmq.participantid = pgm.ParticipantID 
where pmq.moduleid = 46 and  not exists
(select unf.participantid from ParticipantModuleQuestionnaire unf where unf.ParticipantID = pmq.ParticipantID
and unf.ModuleID = 46
and isnull(unf.completedflag,0) <> 0)

皆さん、ありがとうございました

4

2 に答える 2

2

サブクエリを実行して、それAny()がfalseであることを確認できます。私はこれでうまくいくと思います(コンテキストが何であれ、それに合わせるために必要な微調整がいくつかあります)。

var query = 
        from p in ParticipantModulequestionnaire
        join g in ParticipantGroupMember on p.ParticipantId = g.PariticipamtnId
        where p.ModuleId == 46 
         && !ParticipantModuleQuestionnaire.Any(a => 
                        a.ParticipantId = p.ParticipantId
                        && a.ModuleId == 46
                        && (a.CompletedFlag ?? 0) != 0)
        select [p or g, I don't know which].GroupId;
var result = query.Distinct().Count();
于 2013-02-04T23:05:25.097 に答える
1

「存在しない」式の後には、「pmq」に関する述語が続きます。Enumerable.Anyおよび拡張メソッドを参照してくださいEnumerable.All。どちらも使用できます。

于 2013-02-04T23:07:15.843 に答える