This is a migrated thread and some comments may be shown as answers.

Using a JOIN directly is currently not supported

1 Answer 114 Views
LINQ (LINQ specific questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Iftekhar Ivaan
Top achievements
Rank 1
Iftekhar Ivaan asked on 01 Jun 2009, 01:19 AM
Hi,
I am new to OpenAccess. I am having one problem. Can any one help me with the following.

I have two class user and role like following. I need to find out all the role which has specific user
I was trying to do the following but getting error.  How can I do this?


IObjectScope scope = ObjectScopeProvider1.GetNewObjectScope();
scope.Transaction.Begin();

var result = from r in scope.Extent<Role>()
                  join u in scope.Extent<User>()
                  on r.RoleDbId equals u.UserDbId
                  where u.UserName == "iivaan"
                  select r;

scope.Transaction.Commit();

foreach (Role role in result)
{
       Console.WriteLine(role.RoleName);
}

Using a JOIN directly is currently not supported.



public class User
{
 public int UserDbId;
 public String UserName = null;
 public IList<Role> roles = new List<Role>();

}

public partial class Role
{
 public int RoleDbId = -1;
 public String RoleName = null;
 public IList<User> users = new List<User>();

}

1 Answer, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 01 Jun 2009, 09:07 AM
Hello Iftekhar Ivaan,

You can use the Any() method to achieve this:
var result = scope.Extent<Role>().
Where(r => r.users.Any(u => u.UserName == 
"iivaan")); 
 
Another way is to retrieve the object and just use its Roles collection:
User u = (from u in scope.Extent<User>() 
         where u.UserName == "iivaan" 
         select u).First(); 
var result = u.roles; 
Hope that helps.

Kind regards,
Alexander
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
LINQ (LINQ specific questions)
Asked by
Iftekhar Ivaan
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Share this question
or