Using a JOIN directly is currently not supported

2 posts, 0 answers
  1. Iftekhar Ivaan
    Iftekhar Ivaan avatar
    17 posts
    Member since:
    Apr 2006

    Posted 31 May 2009 Link to this post

    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>();

    }

  2. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 01 Jun 2009 Link to this post

    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.
  3. DevCraft banner
Back to Top