title: Pull out records from 3 tables in Linq2Sql
body: <p>I have got 3 tables in my database. Company, Product and Lead. Below are my fields. </p>
  
  <h2>Leads Table:</h2>
  
  <pre><code>SELECT [Id]
        ,[BuySellTypeId]
        ,[ProductName]
        ,[Keywords]
        ,[CategoryId] // categoryid
        ,[SubCategoryId]
        ,[Description]
        ,[ProductImagePath]
        ,[CreationDate]
        ,[ExpiryDate]
        ,[CompanyId] // company id
        ,[ShortDescription]
        ,[IsExpired]
        ,[IsActive]
    FROM [BuySell]
  </code></pre>
  
  <h2>Products Table:</h2>
  
  <pre><code>SELECT   
          Id, 
          Name, 
          Description, 
          ImagePath, 
          CompanyId, //company id
          Keywords, 
          CategoryId,  // categoryid
          SubCategoryId, 
          PostedDate, 
          ExpiryDate, 
          ShortDescription, 
          IsActive,                       
          IsExpired
  FROM  Products
  </code></pre>
  
  <p>I have one more table "<strong>Company</strong>" whose reference is shown above in the two tables. My requirement is to pull out all companies that exists in above tables, Products and BuySell in same categories.
  For example If I want to see all companies of CategoryId = 15, then it will pull all companies with categoryid= 15 from buysell and products table. Obviously there will be redundancy, so i will use <code>Distinct()</code> to extract distinct items.</p>
  
  <p>My Linq2Sql Biz layer method</p>
  
  <pre><code>        /// &lt;summary&gt;
          /// Returns all companies by category id that exists in Lead and Products
          ///table
          /// &lt;/summary&gt;
          /// &lt;param name="categoryId"&gt;category id as integer&lt;/param&gt;
          /// &lt;param name="take"&gt;records to take&lt;/param&gt;
          /// &lt;param name="skip"&gt;records to skip&lt;/param&gt;
          /// &lt;returns&gt;List of companies&lt;/returns&gt;
          public static IList GetCompaniesByCategory(int categoryId, int take, int skip)
          {
              return (from c in Context.Companies
                     join bs in Context.BuySells on c.CompanyId equals bs.CompanyId
                     join p in Context.Products on c.CompanyId equals p.CompanyId
                     where bs.CategoryId == categoryId || p.CategoryId==categoryId
                     select new
                                {
                                    c.CompanyId,
                                    c.CompanyName,
                                    c.Country.Flag,
                                    c.Profile,
                                    c.IsUsingSMSNotifications,
                                    c.IsVerified,
                                    c.MembershipType,
                                    c.RegistrationDate, c.ShortProfile,
                                }).Skip(skip).Take(take).Distinct().ToList();
          }
  </code></pre>
  
  <p>But the above code return me 0 items. When i design its sql , see below, </p>
  
  <pre><code>SELECT     dbo.Company.CompanyId, dbo.Company.CompanyName, dbo.Company.Name, dbo.Company.IsVerified, dbo.Company.IsUsingSMSNotifications, 
                        dbo.Company.CompanyLogo, dbo.Company.RegistrationDate, dbo.Company.Profile
  FROM         dbo.BuySell INNER JOIN
                        dbo.Company ON dbo.BuySell.CompanyId = dbo.Company.CompanyId LEFT OUTER JOIN
                        dbo.Products ON dbo.Company.CompanyId = dbo.Products.CompanyId
  WHERE     (dbo.BuySell.CategoryId = 1) AND (dbo.Products.CategoryId = 1)
  </code></pre>
  
  <p>i am able to get the company from BuySell but not from Product. So please help me. <code>I need the LINQ equivalent statement. To replace the above cs code.</code></p>