title: How to join with LinQ to (typed) dataset?
body: <p>i recently upgraded VS 2005 to 2010 and am fairly new to LinQ. Maybe somebody can put me in the right way. </p>
  
  <p><strong>Background</strong>:
  I have a typed dataset and have the standard SQLMembershipProvider extended with a Table AccessRule. So a role can have infinitely AccessRules(f.e. "Administrator" has "DeleteCustomer"). I use a custom membership provider that inherits from SqlMemberShipProvider and has an overloaded function hasAccess(one with a memory-dataset as parameter and the other uses the database directly).</p>
  
  <p>This is the complete Model:</p>
  
  <p><img src="https://i.stack.imgur.com/r2jcc.jpg" alt="enter image description here"></p>
  
  <p>Now i need to know f.e. if a User with UserID=<code>'89f9ea8d-8ae1-460b-a430-aa433261feec'</code> has AccessRule  "DeleteCustomer". </p>
  
  <p>In SQL it would be something like this:</p>
  
  <pre><code>SELECT     CASE WHEN aspnet_AccessRule.idAccessRule IS NULL THEN 0 ELSE 1 END AS Access
  FROM         aspnet_RoleAccessRule INNER JOIN
                        aspnet_AccessRule ON aspnet_RoleAccessRule.fiAccessRule = aspnet_AccessRule.idAccessRule INNER JOIN
                        aspnet_Roles ON aspnet_RoleAccessRule.fiRole = aspnet_Roles.RoleId INNER JOIN
                        aspnet_UsersInRoles ON aspnet_Roles.RoleId = aspnet_UsersInRoles.RoleId
  WHERE (aspnet_UsersInRoles.UserId = @UserID) AND    (aspnet_AccessRule.RuleName =@RuleName) 
  </code></pre>
  
  <p><strong>In short</strong>: </p>
  
  <p>how do i  get from <code>aspnet_UsersInRoles</code> to<code>aspnet_AccessRule</code> with LinQ?</p>
  
  <p>Thank you in advance...</p>
  
  <p><strong>Edit</strong>:</p>
  
  <p>Although C# is also welcome, i'm preferring VB.Net.</p>
  
  <p>This is what i have, but it doesn't work. </p>
  
  <pre><code>Dim query = From accRule In dsAuth.aspnet_AccessRule _
                          From roleAccRule In dsAuth.aspnet_RoleAccessRule _
                          From role In dsAuth.aspnet_Roles _
                          From userRole In dsAuth.aspnet_UsersInRoles _
                          Where roleAccRule.fiAccessRule = accRule.idAccessRule _
                          And roleAccRule.fiRole = role.RoleId _
                          And userRole.RoleId = role.RoleId _
                          And userRole.UserId = userID And accRule.RuleName = accessRule
              Select accRule.idAccessRule 
  Return query.Any
  </code></pre>
  
  <p>I get a <code>"Definition of method SelectMany is not accessible in this context"</code> compiler warning and the second<code>From</code> is highlighted.
  I assume it has something to do with the composite-keys in aspnet_RoleAccessRule and aspnet_UsersInRoles.  Any suggestions?</p>
  
  <p>This gives the same exception on the first comma:</p>
  
  <pre><code>Dim query = From accRule In dsAuth.aspnet_AccessRule, _
             roleAccRule In dsAuth.aspnet_RoleAccessRule, _
             role In dsAuth.aspnet_Roles, _
             userRole In dsAuth.aspnet_UsersInRoles _
             Where accRule.idAccessRule = roleAccRule.fiAccessRule _
             And roleAccRule.fiRole = role.RoleId _
             And userRole.RoleId = role.RoleId _
             And userRole.UserId = userID And accRule.RuleName = accessRule
       Select accRule.idAccessRule
  Return query.Any
  </code></pre>
  
  <p>This is the join syntax but with similar error(<code>Join</code> is not accessible in context..):</p>
  
  <pre><code>Dim userID As Guid = DirectCast(Membership.GetUser.ProviderUserKey, Guid)
          Dim query = From accRule In dsAuth.aspnet_AccessRule _
                         Join roleAccRule In dsAuth.aspnet_RoleAccessRule _
                         On accRule.idAccessRule Equals roleAccRule.fiAccessRule _
                         Join role In dsAuth.aspnet_Roles _
                         On role.RoleId Equals roleAccRule.fiRole _
                         Join userRole In dsAuth.aspnet_UsersInRoles _
                         On userRole.RoleId Equals role.RoleId _
                         Where userRole.UserId = userID And accRule.RuleName = accessRule
                   Select accRule.idAccessRule
          Return query.Any
  </code></pre>
  
  <hr>
  
  <p><strong>Solution</strong>: I've forgotten to import the Namespace <code>System.LinQ</code>. All these queries are working.</p>
  
  <p>Side note: the Join-Syntax is by far the fastest query. Have a look at my followup-question: <a href="https://stackoverflow.com/questions/5551264/why-is-linq-join-so-much-faster-than-linking-with-where">Why is LINQ JOIN so much faster than linking with WHERE?</a></p>