linq to sql - Help with LinqtoSql -


I am using the repository pattern and I want to write a method that receives a role and the user's Iqueryable Returns to that role (I'm not sure if it will be the right way to get the right object or roll_id ...) In any case, how can I do this? I do not like the query structure, I like the Linux method structure. Users and roles There are many people in the table joining Users_roles.

  Personal Classes Datacontex DB = New Class Datacente (); Public IQueryable GetByRole {Return db.Users.Where ();}   

Maybe try something like this:

  Public IQueryable & lt; User & gt; GetByRoleId (role role) {returns db.UsersRoleJoinTable.Where (ur = & gt; ur.Role == role). Selection (ur = & gt; ur.User);}  

Where UsersRoleJoinTable

Update : Selection (ur => ur.User ) Is saying linq. For each line "db.UsersRoleJoinTable.Where" (ur => ur.Role == role) "came back" by the user we are connected to the ErsRoleJoinTable object If you want a list of user ID instead, then you select By (ur => ur.id) linq can only be used to select user.id. Think of selecting Linq "Do this for every line and return it to the list instead of the original line"

< P> This is a downside of the approach, I in this case the world I am generating SQL to obtain the rows from the Insert Linq table (UsersRoleJoinTable) and then returned for each line, executing another query to see the user. I may be wrong on this Yes, to check the SQL generated by:

  string sql_query = db.UsersRoleJoinTable.Where (ur = & gt; ur.Role == role). Select ur = & gt; U.User) .restring ();  

and then print the value of sql_query See in REN or debug mode. If Linq is actually doing many queries, then I think that the best solution is to create a visual or stored function in SQL Server that users connected to the role and view Visual Studio Designer Or to add stored procedure so that you can call such a scene:

  db.GetUsers (role_id) // if the gateways are using the store process Not so  

or

  Db.UsersByRoleView.where (ur = & gt; Ur.role_id == pass_role_id) // if UsersWhyRoleView is using the view  

Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -