I've been thinking this for a while. Is there an easy way to use the result querying a database twice without storing the result of the query in some variable? Say I have a
string ResearchAdmin;
where I want to put the 'FirstName' and 'Surname' found in 2 different columns in a 'ProjectResearcher' table in the database. Can I query the database just once (using say entity framework), and get both columns without storing the entire table's data.
To illustrate my point, doing the code below will I think query the database twice, once to get the 'FirstName', once to get the 'Surname':
ResearchAdmin = db.ProjectResearcher.FirstOrDefault(r => r.ProjectId == project.ProjectId).Researcher.FirstName + " " + db.ProjectResearcher.FirstOrDefault(r => r.ProjectId == project.ProjectId).Researcher.Surname
To run the query once I can do the following:
Researcher researchAdmin = db.ProjectResearcher.FirstOrDefault(r => r.ProjectId == project.ProjectId).Researcher;
String researchAdminName = researchAdmin.FirstName + " " + researchAdmin.Surname;
What I'm wondering is if I can do the first option somehow without querying the database twice.