开发者

How can i convert my Sql codes to Linq?

开发者 https://www.devze.com 2023-01-15 06:35 出处:网络
i try to convert my SQL code to linq but i cannot: Alter PROCEDURE sp_MatchCTallyToTask AS BEGIN select * from Task where MPDReference in(select MPDReference from Task

i try to convert my SQL code to linq but i cannot:


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.Se开发者_运维问答lect(tsk => tsk.MPDReference).AsQueryable())).ToList());

        }


You can import the stored procedure into your LINQ model, and then simply call the stored procedure.

You will have the benefits of LINQ, without rewriting everyting.


You don't need to do it like that. Corresponding code in sql would look like this:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消