none
Can any one help me convert this SQL query to a Linq Query? RRS feed

  • Question

  • Can some one let me know how to convert this to linq?

    SELECT CAL.thisDate as OrderDate,[orderID],[customerName],[street],[phone],[city],[state],[postal],[country]
          ,Parts.mfgPartNumber, Parts.mfgPartNumber,Model.model, Cat.categoryName, [quantityOrdered]
      FROM [SCM].[WEB].[Sales] AS Sales
      INNER JOIN SCM.Dimensions.Calendar as CAL
      ON CAL.dateKey=Sales.dateKey
      INNER JOIN SCM.Dimensions.MFGParts AS Parts
      ON Parts.mfgPartKey=Sales.mfgKey
      INNER JOIN SCM.Dimensions.Model AS Model
      ON Model.modelKey=Parts.modelKey
      INNER JOIN SCM.Dimensions.Category AS Cat
      ON CAT.categoryKey=Parts.categoryKey
    
      WHERE orderID=2100003612


    Saturday, May 18, 2013 4:01 AM

Answers

  • I think I got it, I just hope the data is accurate. I am going to verify.

                    var data = from sal in search.Sales
                               join date in search.Calendars on sal.dateKey equals date.dateKey
                               join part in search.MFGParts on sal.mfgKey equals part.mfgPartKey
                               join mod in search.Models on part.modelKey equals mod.modelKey
                               join cat in search.Categories on part.categoryKey equals cat.categoryKey
                               where orderNumTxtBox.Text == sal.orderID.ToString()
                               select new
                               {
                                   date.thisDate,
                                   sal.orderID,
                                   sal.customerName,
                                   sal.phone,
                                   sal.street,
                                   sal.city,
                                   sal.postal,
                                   sal.country,
                                   part.mfgPartNumber,
                                   mod.modelName,
                                   cat.categoryName,
                                   part.cost,
                                   sal.quantityOrdered
                               };

    Saturday, May 18, 2013 4:59 AM

All replies

  • I think I got it, I just hope the data is accurate. I am going to verify.

                    var data = from sal in search.Sales
                               join date in search.Calendars on sal.dateKey equals date.dateKey
                               join part in search.MFGParts on sal.mfgKey equals part.mfgPartKey
                               join mod in search.Models on part.modelKey equals mod.modelKey
                               join cat in search.Categories on part.categoryKey equals cat.categoryKey
                               where orderNumTxtBox.Text == sal.orderID.ToString()
                               select new
                               {
                                   date.thisDate,
                                   sal.orderID,
                                   sal.customerName,
                                   sal.phone,
                                   sal.street,
                                   sal.city,
                                   sal.postal,
                                   sal.country,
                                   part.mfgPartNumber,
                                   mod.modelName,
                                   cat.categoryName,
                                   part.cost,
                                   sal.quantityOrdered
                               };

    Saturday, May 18, 2013 4:59 AM
  • Hi Aaron,

    Thanks for sharing your solution here.

    Have a nice day!

    Best regards,


    Chester Hong
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, May 20, 2013 5:35 AM
    Moderator