如何使这个SQL中的LINQ to SQL?(How to make this SQL in LIN

2019-09-18 15:13发布

我熟悉的方式SQL的作品,但与LINQ to SQL的工作给了我一个头痛的问题。 我有以下查询,但我不能将其更改为LINQ to SQL的。 有人可以帮我这个查询或解释我如何来解决这个上了呢?

 SELECT
         DISTINCT Pr.Pcode_,
         Pr.Omschrijving,
         Pt.TypeOmschr 
    FROM 
        Projecten AS Pr
    INNER JOIN 
        ProjectTypen AS Pt 
        ON Pr.ProjType_ = Pt.TypeID 
        AND
        Pr.Status NOT IN ( 'Afgerond', 'Afgewezen' ) 
        LEFT OUTER JOIN 
        Personeel AS Pe
        ON Pr.SeniorId_ = Pe.PerId_ 
        OR 
        Pr.CorId_ = Pe.PerId_
        WHERE  
        ( Pe.Naam LIKE '%%' ) 
         OR  
        ( Pr.Omschrijving LIKE '%%' ) 
        OR
        ( Pr.Pcode_ LIKE '%%' ) 
        OR 
       ( Pt.TypeOmschr LIKE '%%' )
        ORDER  BY 
        Pr.Pcode_

编辑:
我有以下L2S,但它无法正常工作。 我收到以下错误:“PE”这个名字是不是在范围上的“等于”左侧。 我想这个问题是左加入,但该如何解决?

    from Pr in _db.Projectens  
    join Pt in _db.ProjectTypens on Pr.ProjType_ equals Pt.TypeID  
    join Pe in _db.Personeels on ((Pr.SeniorId_ == Pe.PerId_) || (Pr.SeniorId_ == Pe.PerId_)) into P  
    where Pr.Pcode_.Contains(search) || Pr.Omschrijving.Contains(search) || Pt.TypeOmschr.Contains(search) || Pe.Naam.Contains(search)  
    select new SearchProjectViewModel {  
        ProjectCode = Pr.Pcode_,  
        ProjectName = Pr.Omschrijving,  
        ProjectType = Pt.TypeOmschr  
    };

Answer 1:

我认为

join Pe in _db.Personeels on ((Pr.SeniorId_ == Pe.PerId_) || (Pr.SeniorId_ == Pe.PerId_)) into P

应该

join Pe in _db.Personeels on ((Pr.SeniorId_ equals Pe.PerId_) || (Pr.SeniorId_ equals Pe.PerId_)) into P

尝试,让我知道,如果这个工程。



文章来源: How to make this SQL in LINQ to SQL?