views:

49

answers:

2

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.Select(tsk => tsk.MPDReference).AsQueryable())).ToList());

        }
A: 

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.

GvS
A: 

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.

Denis Valeev