gpt4 book ai didi

asp.net-mvc-3 - 如何在 LINQ to SQL 中制作此 SQL?

转载 作者:行者123 更新时间:2023-12-05 00:03:19 25 4
gpt4 key购买 nike

我熟悉 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”不在“equals”左侧的范围内。我猜问题出在左连接上,但解决方案是什么? p>

    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
};

最佳答案

我觉得

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

试试看,如果可行,请告诉我。

关于asp.net-mvc-3 - 如何在 LINQ to SQL 中制作此 SQL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11226112/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com