views:

55

answers:

3

So far after watching the tutorial videos on link, im fine accessing one data table and dealing with the results. On putting this into practice at the office I am faced with a lot of joins that I need to convert to LINQ...

SELECT Modules.TemplateFileName FROM Modules INNER JOIN Grouping ON Modules.ID = Grouping.ModuleID WHERE (Grouping.ID = @id)

(@id comes from querystring)

Could anyone please show me an example of the syntax needed to make it work?

Thanks and regards.

+1  A: 

If you are looking at perforing JOINS in LINE to SQL, here is an example:

AdventureWorksDataContext aw = new AdventureWorksDataContext();

    aw.Log = Console.Out;

    var entities = from e in aw.Employees
                   join ea in aw.EmployeeAddresses on e.EmployeeID equals ea.EmployeeID
                   join a in aw.Addresses on ea.AddressID equals a.AddressID
                   join c in aw.Contacts on e.ContactID equals c.ContactID

                   where e.EmployeeID == employeeID

                   select new
                   {
                       Title = e.Title,
                       FirstName = c.FirstName,
                       LastName = c.LastName,
                       City = a.City,
                       AddressID = ea.AddressID
                   };

You can do a google serach and find a lot of example on it.

Bhaskar
Sounds like you don't have an actual question, but just want us to do your work for you, doesn't it?
bzlm
Here's a good one: http://www.hookedonlinq.com/LINQtoSQL5MinuteOverview.ashx
bzlm
if you have nothing helpful to add. Rather add nothing at all.
Phil Sanderson
+1  A: 

This should get you started...

var fileName = from mod in db.Modules
join groupings in db.Grouping on mod.ID equals groupings.ModuleID
where groupings.ModuleID == idFromQueryString
select new { mod.TemplateFileName }
EricAppel
+1  A: 
var example = from m in dataContext.Modules
              join g in dataContext.Grouping on m.ID equals g.ModuleID
              where g.ID == groupID
              select new { m.TemplateFileName };
mynameiscoffey