日期:2014-05-17 浏览次数:20577 次
public User SelectByName(string name) { using (CleverTourEntities context = new CleverTourEntities()) { var user = from u in context.User where u.Name == name select u; return user;//在这会报错,改为return (User)user;就正常了 } }
return user;改为 if (user.Count() > 0) { return user.FirstOrDefault(); }
------解决方案--------------------
public User SelectByName(string name)
{
using (CleverTourEntities context = new CleverTourEntities())
{
return context.User.FirstOrDefault(u=>u.Name == name);
}
}
------解决方案--------------------
顶楼上的,lambda表达式,正解