1
votes

I have a stored procedure that I'm converting to LINQ, but I'm a little stuck. Here's the SQL:

    select 
      @name                             = tp.Name
,     @Entity                           = tc.Entity
,     @Name                             = tc.Name
,     @ID                               =  tpt.ID
,     @Code                             =  tptr.Code  

    from tbltprop tp 

    Left join tblcol tc                                on ( tc.id = tp.ID )
    Left join tblPropday  tpt               on ( tpt.Id = tp.Id )
    Left join tblProperResult tptr   on (tptr.ID = tpt.Id )

    where tp.id               = @chsarpID1 //input ID i get in c#
    and     tpt.Id = @chsarpID2

I understand how to do a single join, but I'm having some trouble making a multiple join work. How would one go about this?

1
Did you have a specific problem with this conversion that we could help you with? Or did you just want us to write your code for you...Alexander R
Please re write the same code in C#, i don't no syntax :(, i'm dumb in SQL query syntax, sorry and thanks for ur replyNaruto
Unfortunately StackOverflow is a Q&A site, we tend to not write code for people. I'd suggest you read and learn about LINQ and SQL and, of course, come back if you get stuck on any specific bits. Good luck!Alexander R
na, i know linq sql.. but my doubt is how to write the multiple joins in C#, single join somehow i learnt but multiple join i don no :(Naruto

1 Answers

2
votes

This might help you.......

var values= from tp in tbltprop
            join tb in tblcol ON tp.id equals tb.id into gj
            from gjd in gj.DefaultIfEmpty()
            join tpt in tblPropday ON tp.id equals tpt.id into gk
            from gkd in gk.DefaultIfEmpty()
            join tptr in tblProperResult ON tp.id equals tptr.id into gl
            from gld in gl.DefaultIfEmpty()
            where tp.id == @charpID1 && gkd.Id == @CharpID2
            select new 
                   { 
                       TpName = tp.Name, 
                       Entity = gjd.Entity, 
                       TPTName = gjd.Name, 
                       ID = gkd.ID, 
                       Code = gld.Code
                   };