Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. Convert SQL to Linq

Convert SQL to Linq

Scheduled Pinned Locked Moved LINQ
databasecsharplinq
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    myousufq
    wrote on last edited by
    #1

    Hi, Can any body convert below sql query into LINQ for me please SELECT ProjectCategory.ProjectCategoryName FROM ProjectCategoryDetails INNER JOIN ProjectCategory ON ProjectCategoryDetails.ProjectCategoryID = ProjectCategory.ProjectCategoryID INNER JOIN ProjectContentInfoSample ON ProjectCategoryDetails.ProjectID = ProjectContentInfoSample.ProjectID WHERE (ProjectCategoryDetails.ProjectID = 'Pr-11') Many Thanks

    M 1 Reply Last reply
    0
    • M myousufq

      Hi, Can any body convert below sql query into LINQ for me please SELECT ProjectCategory.ProjectCategoryName FROM ProjectCategoryDetails INNER JOIN ProjectCategory ON ProjectCategoryDetails.ProjectCategoryID = ProjectCategory.ProjectCategoryID INNER JOIN ProjectContentInfoSample ON ProjectCategoryDetails.ProjectID = ProjectContentInfoSample.ProjectID WHERE (ProjectCategoryDetails.ProjectID = 'Pr-11') Many Thanks

      M Offline
      M Offline
      myousufq
      wrote on last edited by
      #2

      Hi All, I have resolved it myself from p in ProjectCategories join b in ProjectCategoryDetails on p.ProjectCategoryID equals b.ProjectCategoryID join c in ProjectContentInfoSamples on b.ProjectID equals c.ProjectID where c.ProjectID == "Pr-09" select new { p.ProjectCategoryName } Many thanks

      R 1 Reply Last reply
      0
      • M myousufq

        Hi All, I have resolved it myself from p in ProjectCategories join b in ProjectCategoryDetails on p.ProjectCategoryID equals b.ProjectCategoryID join c in ProjectContentInfoSamples on b.ProjectID equals c.ProjectID where c.ProjectID == "Pr-09" select new { p.ProjectCategoryName } Many thanks

        R Offline
        R Offline
        r3m1x
        wrote on last edited by
        #3

        If you have defined the relationships in the data context (.dbml), linq has what i would say lazy loading intellisense which gives you a way to do complex query in a simple linq friendly way. Here is an example related to your query: using (dataContext db = new dataContest) { var q = from p in db.ProjectCatergories where p.ProjectCategoryDetails.ProjectContentInfoSamples.ProjectID == "Pr-09" select new { p.projectCategoryName }; } So basically linq joins the tables automatically and that is one of the reasons I believe linq is so powerful! Hope this helps!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups