locked
Question about Query Method _Filter RRS feed

  • Question

  • First, I'm new to Lightswitch and any type of design in general, limited knowledge...

    Here's my question.  I've made a database that includes a table for "Projects" and a table for "Users".  A user can be assigned to many projects and a project can be assigned to many users.  I created a "ProjectsToUser" mapping table with Many-One relationships to both "Projects" and "Users" in order for this many-to-many relationship to function.  What I would like to be able to do is within the Projects_Filter method is create a filter that limits the logged in user to see only projects he/she is assigned to (via this many to many relationship).  When a user is created in the app a listbox allows me to assign whatever projects are necessary to that user.  I just can't wrap my head around how to accomplish this.

    I understand how to use permissions and roles in the _Filter method to create some row level security which has been helpful in other parts of this app.  As for projects, what a user has access to can change on a daily basis so the idea of just editing the user and moving projects to and from the list box is an ideal situation.

    Sorry if I'm confusing here, I'm confusing myself actually.

    Wednesday, February 20, 2013 11:53 PM

Answers

  • I assume you have a way to link or identify the registered or logged in user to from your Users entity.  Based on this I think the following _Filter expression would accomplish what you want.

    partial void Projects_Filter(ref Expression<Func<Project, bool>> filter)
    {
        filter = p => p.ProjectsToUser.Users.Any(u => u.RegisteredUser == this.Application.User.Name);
    }

    What this conceptually says is return the project if its ProjectsToUser has any assigned User(s) that is the associated/tied to the current user.
    Thursday, February 21, 2013 5:09 PM

All replies

  • I assume you have a way to link or identify the registered or logged in user to from your Users entity.  Based on this I think the following _Filter expression would accomplish what you want.

    partial void Projects_Filter(ref Expression<Func<Project, bool>> filter)
    {
        filter = p => p.ProjectsToUser.Users.Any(u => u.RegisteredUser == this.Application.User.Name);
    }

    What this conceptually says is return the project if its ProjectsToUser has any assigned User(s) that is the associated/tied to the current user.
    Thursday, February 21, 2013 5:09 PM
  • snomis,

    Right on!  Thanks so much... had to slightly modify but this got everything working perfectly for me.

    Billy

    Friday, February 22, 2013 2:31 AM
  • Thank you snomis, I had this same problem and your solution solved it.

    Thursday, June 6, 2013 1:30 PM