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 u.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;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.