Convert SQL to Linq
-
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
-
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
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
-
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
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!