Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# LINQ左连接不';我不能正常工作_C#_Sql_Entity Framework_Linq - Fatal编程技术网

C# LINQ左连接不';我不能正常工作

C# LINQ左连接不';我不能正常工作,c#,sql,entity-framework,linq,C#,Sql,Entity Framework,Linq,我在林克的左路有点不对劲 我的SQL查询工作正常: VoilierInscrit vi 在vi.idCourse=co.Id\u课程上加入课程co 在co.Id\u Course=ep.idcourse上加入ePreve ep vi.Id_VoilierInscrit=pe.VoilierInscrit上的左连接Penalite pe 在ep.Id_epruve=tp.IDepreuve上加入Tps tp 其中tp.IDvoilierInscrit=vi.Id\u VoilierInscrit

我在林克的左路有点不对劲

我的SQL查询工作正常:

VoilierInscrit vi
在vi.idCourse=co.Id\u课程上加入课程co
在co.Id\u Course=ep.idcourse上加入ePreve ep
vi.Id_VoilierInscrit=pe.VoilierInscrit上的左连接Penalite pe
在ep.Id_epruve=tp.IDepreuve上加入Tps tp
其中tp.IDvoilierInscrit=vi.Id\u VoilierInscrit
临时订单
结果('TEMP'和'Duree'为时间跨度):

但是,当我在LINQ中执行此操作时,会出现以下错误: '无法将空值分配给System.TimeSpan类型为不可空的成员'

var resultat = from vi in db.VoilierInscrit
               from co in db.Course.Where(x => vi.idCourse == x.Id_Course)
               from ep in db.Epreuve.Where(x => co.Id_Course == x.idcourse)
               from pe in db.Penalite.Where(x => vi.Id_VoilierInscrit == x.VoilierInscrit)
               .DefaultIfEmpty()
               from tps in db.Tps.Where(x => ep.Id_Epreuve == x.IDepreuve)
               where tps.IDvoilierInscrit == vi.Id_VoilierInscrit

               select new
               {

                   temps = tps.Temps,
                   SerialNumber = vi.NumeroSerie,
                   duree = pe.Duree
               };

我真的不知道问题出在哪里-我的LINQ语法似乎是正确的。

好吧,第一个值得注意的事情是SQL查询有1个外部连接,而LINQ-4。第二个是LINQ连接到
Penatilte
x=>ep.Id\u Epreuve==x.idepreuve
)与SQL查询中使用的不同。@IvanStoev谢谢,我已经重写了我的查询并编辑了我的帖子,现在我遇到了一个错误“这似乎是一个很好的步骤:'空值不能分配给System.TimeSpan类型的成员,这是一个不可为空的'Use
duree=(DateTime?)pe.Duree
你做完了吗:)@IvanStoev非常感谢Ivan,我学到了很多!!它现在工作得很好!祝你过得愉快,伙计!首先值得注意的是,SQL查询有1个左外连接,而LINQ-4。第二个是LINQ连接到
Penatilte
x=>ep.Id\u Epreuve==x.idepreuve
)与SQL查询中使用的连接不同。@IvanStoev谢谢,我重写了我的查询并编辑了我的帖子,现在我遇到了一个错误,这似乎是一个很好的步骤:“空值不能分配给System.TimeSpan类型的成员,这是一个不可为空的'Use
duree=(DateTime?)pe.duree
你完成了吗:)@IvanStoev非常感谢Ivan,我学到了很多!!它现在工作得很好!祝你过得愉快,伙计!
var resultat = from vi in db.VoilierInscrit
               from co in db.Course.Where(x => vi.idCourse == x.Id_Course)
               from ep in db.Epreuve.Where(x => co.Id_Course == x.idcourse)
               from pe in db.Penalite.Where(x => vi.Id_VoilierInscrit == x.VoilierInscrit)
               .DefaultIfEmpty()
               from tps in db.Tps.Where(x => ep.Id_Epreuve == x.IDepreuve)
               where tps.IDvoilierInscrit == vi.Id_VoilierInscrit

               select new
               {

                   temps = tps.Temps,
                   SerialNumber = vi.NumeroSerie,
                   duree = pe.Duree
               };