0 Project.
I have property
public string UserName { get; set; }
can i set this property to retrieve user name using linq statement?
from u in context.Users
where 开发者_StackOverflowu.UserID==session["UserID"]
select u.UserName
something like this
public string UserName { get value;
set from u in context.Users
where u.UserID==session["UserID"]
select u.UserName; }
Try
public string UserName {
get {
return (from u in context.Users
where u.UserID==session["UserID"]
select u.UserName).SingleOrDefault();
}
}
The get part of your code should look like this if you try to return the UserName
get
{
var result = (from u in context.Users
where u.UserID==session["UserID"]
select u.UserName).FirstOrDefault();
return result;
}
精彩评论