I am trying to return the Actual Value in this query but I only get the Expression. Can someone point me in the right direction please.
public static String NurseName(Guid? userID)
{
var nurseName = from demographic in context.tblDemographics
where demographic.UserID == userID
select new {FullName = demographic.FirstName +" " + demographic.LastName};
String nurseFullName = nurseName.ToString();
return nurseFullName;
}
nurseFullName ends up as –> SELECT ([t0].[FirstName] + @p1) + [t0].[LastName] AS [FullName]
FROM [dbo].[tblDemographics] AS [t0]
WHERE ([t0].[UserID]) = @p0
In the above nurseName has the IQueryable expression, so it hasn’t executed anything. Its when you enumerate on it, that the query is called. That’s also the case when you call methods like SingleOrDefault.
If you were to use your original query expression instead, you can:
Difference between Single vs. SingleOrDefault is that the later allows an empty result.
Difference between First vs. Single is that the later prevents more than 1 row.