简体   繁体   English

我如何将我的Sql代码转换为Linq?

[英]How can i convert my Sql codes to Linq?

i try to convert my SQL code to linq but i cannot: 我尝试将我的SQL代码转换为linq,但是我不能:


Alter PROCEDURE sp_MatchCTallyToTask
AS
BEGIN

 select * from Task where MPDReference in(  select MPDReference from Task 
intersect
select ENG_CUSTOMERTALLY_CUSTOMERTASKNUMBER from dbo.ENG_CUSTOMERTALLY)
END
GO


 public List<Task> TaskList()
        {
            return engCtx.Tasks.Where(t => t.MPDReference.Contains(engCtx.ENG_CUSTOMERTALLies.Select(c => c.ENG_CUSTOMERTALLY_CUSTOMERTASKNUMBER).
                Except(engCtx.Tasks.Select(tsk => tsk.MPDReference).AsQueryable())).ToList());

        }

You can import the stored procedure into your LINQ model, and then simply call the stored procedure. 您可以将存储过程导入LINQ模型,然后简单地调用存储过程。

You will have the benefits of LINQ, without rewriting everyting. 您将获得LINQ的好处,而无需重写所有内容。

You don't need to do it like that. 您不需要那样做。 Corresponding code in sql would look like this: sql中的相应代码如下所示:

select * from Task t
join dbo.ENG_CUSTOMERTALLY ect on ect.ENG_CUSTOMERTALLY_CUSTOMERTASKNUMBER = t.MPDReference 

So you need to join those busters in your linq query. 因此,您需要在linq查询中加入这些破坏者。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM