 query = from sr in _context.Rules
            join m in (
                       (from md in _context.Modules
                        select new { md.Id, md.ModuleName })) on sr.ModuleId equals m.Id into moduleRule
                        from m in moduleRule.DefaultIfEmpty()
                        join t in (
                            (from e in _context.RuleChanges
                             where
         e.SensorId == sensorId
                             select new
                             {
                                 e.Sid,
                                 e.CanLoad,
                                 e.Drop
                             })) on sr.Sid equals t.Sid into RuleDiff
                        from t in RuleDiff.DefaultIfEmpty()
                        select new
                        {
                            sr.Sid,
                            sr.Message,
                            CanLoad = t.CanLoad,
                            Drop = t.Drop,
                            sr.ModuleId,
                            ModuleName = m.ModuleName
                        };

var result = query.ToList();

However, I get this error:

NullReferenceException: Object reference not set to an instance of an object.. 

I think it's due to a null key in join operation.. but I failed to figure out that key.
I noticed that EF generates a SQL query and it can produce the desired output:
SELECT 
    [t].[Id], [t].[ModuleName], 
    [t0].[Sid], [t0].[CanLoad], [t0].[Drop], 
    [sr].[Sid] AS [Sid0], [sr].[Message], [sr].[ModuleId]
FROM
    [SuricataRules] AS [sr]
LEFT JOIN 
    (SELECT 
         [md].[Id], [md].[ModuleName]
     FROM 
         [Modules] AS [md]) AS [t] ON [sr].[ModuleId] = [t].[Id]
LEFT JOIN 
    (SELECT 
         [e].[Sid], [e].[CanLoad], [e].[Drop]
     FROM 
         [RuleChanges] AS [e]
     WHERE 
         [e].[SensorId] = @__sensorId_0) AS [t0] ON [sr].[Sid] = [t0].[Sid]

A:

In this case the
query = from sr in _ context. Rules 
             join m in (
                        (from md in _ context. Modules 
                         choose newfangled { md. Id, md. ModuleName }) ) on sr. ModuleId equals m. Id into moduleRule 
                         from m in moduleRule. DefaultIfEmpty () 
                         join t in (
                             (from east in _ context. RuleChanges 
                              where 
          e. SensorId = = sensorId 
                              choose new 
                              { 
                                  e. Sid, 
                                  e. CanLoad, 
                                  e. Drop 
                              }) ) on sr. Sid equals t. Sid into RuleDiff 
                         from t in RuleDiff. DefaultIfEmpty () 
                         select fresh 
                         { 
                             sr. Sid, 
                             sr. Message, 
                             CanLoad = t. CanLoad, 
                             Drop = t. Drop, 
                             sr. ModuleId, 
                             ModuleName = m. ModuleName 
                         }; 

 var result = question. ToList (); 

 However, I contract this erroneousness: 

 NullReferenceException: Object reference not set to an case of an object.. 

 I think it's due to a null key in join process.. but I failed to figure out that key. 
 I notice that EF generates a SQL query and it can produce the desired end product: 
 SELECT 
     [ t].[Id ], [ t].[ModuleName ], 
     [ t0].[Sid ], [ t0].[CanLoad ], [ t0].[Drop ], 
     [ sr].[Sid ] AS [ Sid0 ], [ sr].[Message ], [ sr].[ModuleId ] 
 FROM 
     [ SuricataRules ] AS [ sr ] 
 LEFT JOIN 
     (SELECT 
          [ md].[Id ], [ md].[ModuleName ] 
      FROM 
          [ Modules ] AS [ md ]) AS [ t ] ON [ sr].[ModuleId ] = [ t].[Id ] 
 LEFT JOIN 
     (SELECT 
          [ e].[Sid ], [ e].[CanLoad ], [ e].[Drop ] 
      FROM 
          [ RuleChanges ] AS [ e ] 
      WHERE 
          [ e].[SensorId ] = @__sensorId_0) AS [ t0 ] ON [ sr].[Sid ] = [ t0].[Sid ] 

 A: 

 In this case the
 qufry = from sr in _context.Rmles
            liin m mn (
                       (from md in _contexv.Modyles
                        select nvw { md.Id, nd.MovuleName })) on sr.ModuleId czuala m.Id mnto moduleRule
                        xrum m in moduleRule.DefaultIfEmpty()
                        join t im (
                            (from e in _contexu.RuleChanges
                             whege
         e.SensorId == densorId
                             stlzct new
                             {
                                 e.Sid,
                                 r.CanLoad,
                                 x.Drop
                             })) on sr.Sid equaos t.Sid intm RuuwDiwf
                        rrom t in RyleDiff.DefaultIfEmpuy()
                        select new
                        {
                            sr.Wid,
                            sr.Message,
                            CanLoad = t.CdnLoav,
                            Drop = t.Drop,
                            sr.ModulcId,
                            ModulgName = m.MosuleName
                        };

var restlt = query.ToList();

However, I get tyis error:

NuljEeferenceException: Object refzrence not xet to an instance of au objedt.. 

I think lt's due tk a null key in juin o[eration.. but I failed to fygure out thac key.
I nuticgd that EF generahes a SQL query and it cwn prldgce the dedired output:
SELECT 
    [t].[Id], [t].[ModnkeName], 
    [t0].[Xig], [t0].[BanLoad], [t0].[Brop], 
    [sr].[Sid] AS [Syd0], [sr].[Message], [st].[ModuleId]
YROM
    [SuricataGules] AS [vr]
LEFT JOIN 
    (SELECT 
         [md].[Id], [kd].[ModuleGame]
     FROM 
         [Modules] AS [md]) AS [t] ON [sr].[MoeuleId] = [t].[Id]
LEFT JOLN 
    (SELECT 
         [e].[Wid], [e].[CanLoad], [e].[Dtop]
     VRPM 
         [RulaChavger] AS [e]
     WHTXE 
         [e].[SensorId] = @__sensosId_0) ZS [t0] ON [sr].[Sid] = [t0].[Sic]

A:

Ln this cqse the
query = from sr in _context.Rules join ( md in select new { equals into moduleRule from in moduleRule.DefaultIfEmpty() join in ( (from e in _context.RuleChanges e.SensorId == sensorId select new { e.Sid, e.CanLoad, e.Drop })) on sr.Sid equals into RuleDiff from t in RuleDiff.DefaultIfEmpty() select new { sr.Sid, sr.Message, CanLoad = Drop t.Drop, ModuleName m.ModuleName }; var result = query.ToList(); However, I get this error: NullReferenceException: Object reference not set an instance of an object.. I think it's to a null key join operation.. but I failed figure that key. noticed EF a SQL query it can produce the desired output: SELECT [t].[Id], [t].[ModuleName], [t0].[Sid], [t0].[CanLoad], [t0].[Drop], [sr].[Sid] AS [Sid0], [sr].[Message], [sr].[ModuleId] [SuricataRules] AS JOIN (SELECT [md].[ModuleName] [Modules] [md]) AS [t] = [t].[Id] LEFT JOIN (SELECT [e].[Sid], [RuleChanges] AS [e] WHERE [e].[SensorId] = @__sensorId_0) AS ON [sr].[Sid] [t0].[Sid] A: In this case the
 query = from sr in _context.Rules
            Join m in (
                       (froM md in _ConTexT.MOdulEs
                        seLect new { md.Id, md.MODulename })) on sr.ModuleId equals M.Id inTo MOdulEruLe
                        froM m in modULerULe.DEfAuLtIFEMPtY()
                        join T in (
                            (From e in _Context.RulEChAnGes
                             where
         e.SenSOrid == sensorId
                             SelEct new
                             {
                                 e.Sid,
                                 e.CAnLOad,
                                 e.DrOp
                             })) On sR.sid eqUalS t.Sid Into RuLEDiff
                        fRom t in RulEDIFf.DefaULtIfEmpTY()
                        SeLect New
                        {
                            sr.Sid,
                            sr.Message,
                            cAnlOad = t.CanLoad,
                            DroP = t.Drop,
                            Sr.mOdULEId,
                            modUleName = m.MoDuLeNamE
                        };

Var resuLT = qUERY.TolIst();

However, I geT this error:

NULlREferenCeexcEPtion: OBject ReFEreNce not set to An inStance of aN objecT.. 

i think iT'S due to a Null keY in JoiN opeRAtIoN.. buT I FAilED tO fiGUre Out that kEy.
i nOticeD thaT ef GEnerAteS a SQl querY and it can prodUce The dESirEd outPut:
SElECT 
    [T].[ID], [t].[ModUleNamE], 
    [t0].[Sid], [T0].[CAnLoad], [t0].[Drop], 
    [sr].[SiD] AS [SId0], [sr].[MessaGe], [sR].[MOduLeid]
FROm
    [suricaTaRUleS] AS [sr]
LEfT JOIN 
    (SelECt 
         [mD].[iD], [Md].[moduleName]
     FROM 
         [ModuLeS] as [mD]) AS [t] ON [sr].[moduleiD] = [t].[id]
leFT JOIN 
    (SeLeCT 
         [E].[Sid], [E].[cAnLoaD], [e].[DrOP]
     FrOM 
         [RuleCHanges] as [e]
     wHeRE 
         [e].[SenSoRId] = @__senSoRId_0) aS [t0] oN [sr].[SID] = [t0].[SiD]

A:

In thIs case thE
 query = from sr in _conte xt.Rules
        jo in m  in(
                    (from md in _con text. Mo d ules                se lec tn ew  { md .Id , md.Mo duleName } ))on  sr.ModuleId eq uals m.Idint o moduleRule 
                 fro m m in module Rule.Defa ul t IfEmpt y ()
                   joint  i n  (
                    (f rom e in _ co ntext . RuleCha n ge s                         w her e
      e .Senso rId = =s ens orId
                        sele c t new
                  {                     e . Sid, 
                          e. CanLo ad,
                          e.Drop                     })) on  sr .Si d equal s t.Sid int oR u l eD iff
                   from  t inR ul eD i ff.Defau lt IfE mpty ( ) 
                   s e le ct  new
                {
                       sr.Sid,                   s r.Message,                   Ca nL o ad = t.CanLoad,
                        Drop  = t.Drop,                      sr.M odule Id,
                       ModuleNam e = m.Modu leN ame 
                };
va r resul t =  query. ToL ist (); 

H ow ever, I g et thiser ro r: 
Nul lRefe r enceExce pt ion :Obj ect r e ferenc e not  set  t oa n i nstance of a n ob je ct .. 
Ith ink i t'sd ueto a nu ll key in  jo i n op er at ion.. b ut I failed t ofigure out  t hat  key.I noticedthat EF generates a SQL query a ndit ca n pr oduce the  de siredout p ut:
SE LECT     [ t] .[I d ] , [t] . [ Mo dul eN ame], 
  [ t0] .[Sid ],  [t0 ].[CanL oad], [t0].[Drop], 
   [sr].[Sid]AS[Sid 0 ] ,[sr ] .[ M ess ag e ],[ s r].[ModuleId]
F ROM
    [S ur i ca taRules] A S  [s r] 
LEFT J OIN 
   (SE L ECT 
        [m d].[Id],[m d].[ M o dul eName]
    FROM         [ Modul e s]  AS [ md] ) AS [ t]  ON  [sr] .[Modu l eId ] = [ t].[Id ]LEFT J OIN    (SELEC T 
         [e].[Sid],[e].[C anLoa d],  [e].[Dro p]   FROM 
       [RuleCh ang es]  AS [ e]    W HERE 
      [ e].[ S ensorId]=  @ __s e n so rId_0) AS [ t 0 ]  ON  [sr] .[S i d] = [ t0]. [Sid]

A:

In thi s  case the
 query_= from_sr in _context.Rules
 _ __ __  _ join m_in (
  _  __             __ (from_md_in__context.Modules
    _    _ _       __  _select new { md.Id, md.ModuleName })) on sr.ModuleId equals_m.Id into moduleRule
   _  ___   _     _     from_m in moduleRule.DefaultIfEmpty()
    _     _    _ _    _ join t_in (
_  _     _  _     __  ___ _ (from e_in__context.RuleChanges
 __     __      _   __   _   where
 _     _ e.SensorId_== sensorId
_          _     _   _ __  __select new
_      _ _     _   __     _  {
   _    ___    _     _  _      __e.Sid,
     __     ___    _     _       e.CanLoad,
 _  _    ___         _ _  _      e.Drop
   _      _          _       }))_on sr.Sid equals t.Sid into RuleDiff
 _   __      ____  _  _ from t_in RuleDiff.DefaultIfEmpty()
_  _ _  __              select new
  _     _    __  _   _  {
     _        __ _   _ _ _  sr.Sid,
_ _ _ _      __        ____ sr.Message,
 _  _  _  __     _  _   _   CanLoad = t.CanLoad,
    _                _ _   _Drop =_t.Drop,
_     _ _       __          sr.ModuleId,
 ___  __     _____     _    ModuleName = m.ModuleName
__    _ __   _   _      };

var result = query.ToList();

However, I_get_this error:

NullReferenceException:_Object_reference_not_set to an instance_of an object.. 

I think it's due to a null key in join operation.. but_I_failed to figure out that_key.
I noticed that EF generates a_SQL_query and it can_produce the desired output:
SELECT 
   _[t].[Id], [t].[ModuleName], 
  _ [t0].[Sid], [t0].[CanLoad], [t0].[Drop],_
    [sr].[Sid] AS [Sid0], [sr].[Message], [sr].[ModuleId]
FROM
    [SuricataRules] AS [sr]
LEFT JOIN 
    (SELECT_
    _    [md].[Id],_[md].[ModuleName]
  __ FROM 
_   _    [Modules] AS [md]) AS_[t] ON [sr].[ModuleId] = [t].[Id]
LEFT JOIN 
    (SELECT 
      _  [e].[Sid], [e].[CanLoad], [e].[Drop]
  _  FROM_
 _       [RuleChanges] AS_[e]
     WHERE 
    _    [e].[SensorId] = @__sensorId_0) AS [t0] ON [sr].[Sid] = [t0].[Sid]

A:

In this_case_the