Can I assign values to user object without looping in query result? I don't need looping there will be only one or no return from the query.
protected user GetU开发者_StackOverflow社区ser(user u, string name, string password)
{
using (DBEntities db = new DBEntities())
{
var selectedUser = from p in db.users
where p.name == name && p.pass == password
select p;
if (selectedUser.Count() == 1)
{
foreach (user us in selectedUser)
{
u.id = us.id;
u.name = us.name;
u.pass = us.pass;
}
}
return u;
}
}
I guess you are looking for:
using (var db = new DBEntities())
{
return db.users.SingleOrDefault(u => u.name == name && u.pass == password);
}
精彩评论