Answered help me to convert sql query to linq query

  • Thursday, March 01, 2012 11:58 AM
     
     

    Hi everyone,

    I am new in LINQ. Please  help  me to convert the following SQL Query into LINQ query. The Query is :

    select ts.CrewID, ts.SignOnID,
    ltrim(rtrim(isnull(mc.FirstName,'')+  isnull(mc.MiddleName,'') + isnull(mc.LastName,''))) as CrewName,
    mr.Rank, ts.SignOnDate,
     (select top 1 Bank_Beneficiary from mCrewBankDetails where CrewID=ts.CrewID order by mCrewBankDetails.CreatedOn desc )Bank_Beneficiary,
    (select top 1 PaymentMode from mCrewBankDetails  join mPaymentMode on mPaymentMode.PaymentModeID = mCrewBankDetails.Bank_PaymentModeID where CrewID=ts.CrewID order by mCrewBankDetails.CreatedOn desc )Bank_PaymentMode,
    (select top 1 Bank_Name from mCrewBankDetails where CrewID=ts.CrewID order by mCrewBankDetails.CreatedOn desc ) as Bank_Name,
    (select top 1 Bank_Branch from mCrewBankDetails where CrewID=ts.CrewID order by mCrewBankDetails.CreatedOn desc )Bank_Branch,
    (select top 1 Bank_AcNo from mCrewBankDetails where CrewID=ts.CrewID order by mCrewBankDetails.CreatedOn desc )as Bank_AcNo,
    (select top 1 Bank_Address from mCrewBankDetails where CrewID=ts.CrewID order by mCrewBankDetails.CreatedOn desc )Bank_Address,
    (select top 1 Bank_SpecialInstructions from mCrewBankDetails where CrewID=ts.CrewID order by mCrewBankDetails.CreatedOn desc )as Bank_SpecialInstructions,
    @Amount as Amount
    from tsignon ts
    join mRank mr on mr.RankID=ts.RankID
    join mCrew mc on mc.CrewID=ts.CrewID
     Where ts.VesselID = @VesselID
     And (ts.SignOffDate IS NULL) 
     And (ts.SignOnDate < DATEADD("D",1,@LastDate))
     Order By mr.Sequence

All Replies

  • Monday, March 05, 2012 5:11 AM
    Moderator
     
     Answered

    Hi ShrutiKasar,

    Welcome to MSDN Forum.

    With such a difficult T-SQL, I suggest you to exectute it directly or use stored procedure. Not all the T-SQL can be translated to Linq smoothly, and, the T-SQL is such complex, thought it can be translated to Linq, when the Linq query statement is executing, it will translate to a more complex T-SQL, it will affect the performance of query.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us