I have a database request which looks as follows:
var userHasProfessions = xy.GetUserProfessions();
var users = sessionService.GetDefaultSession()
.Query<User>()
.Where(a => userProfessions.Contains(a.Profession.Id))
.ToList();
It gets all users that the requesting user is allowed to see, depending on his own profession. Now I wanna restrict that a little more, that he can only see some attributes of the users. Let's say for example:
id -> yes
firstname -> yes
lastname -> yes
address -> no!
Now I tried t change the query to something like:
var userHasProfessions = xy.GetUserProfessions();
var users = sessionService.GetDefaultSession()
.QueryOver<User>()
.SelectList(list => list
.Select(a => a.id)
.Select(a => a.firstname)
.Select(a => a.lastname))
.Where(a => userProfessions.Contains(a.Profession.Id))
.ToList();
Now my question... Is there a way to, for example, make a new List with these attributes and then loop through it? Something like that:
List<string> attributes = new List<string>(){"id", "firstname", "lastname"}
var userHasProfessions = xy.GetUserProfessions();
var users = sessionService.GetDefaultSession()
.QueryOver<User>()
.SelectList(
//loop through attributes
)
.Where(a => userProfessions.Contains(a.Profession.Id))
.ToList();
Thanks in advance :-)
EDIT
To make my question a little bit more clear. I wanna have the attributes that the user is allowed to see, dynmically changeable from a List<string>
outside the query.
How can a achieve that?