Code
using (var ObjectContext = new AgentSystemEntities())
{
string username = "x70";
string entitySQL = "SELECT VALUE u FROM Users AS u WHERE u.UserName = '" + username + "';";
ObjectQuery<Users> query = ObjectContext.CreateQuery<Users>(entitySQL);
string message = "执行的语句:" + query.CommandText + "\n\r";
if (query.Count() > 0)
{
message += query.First().UserNames + "\n\r";
}
else
{
message += "没有数据\n\r";
}
MessageBox.Show(message);
}
using (var ObjectContext = new AgentSystemEntities())
{
string username = "x70";
string entitySQL = "SELECT VALUE u FROM Users AS u WHERE u.UserName = '" + username + "';";
ObjectQuery<Users> query = ObjectContext.CreateQuery<Users>(entitySQL);
string message = "执行的语句:" + query.CommandText + "\n\r";
if (query.Count() > 0)
{
message += query.First().UserNames + "\n\r";
}
else
{
message += "没有数据\n\r";
}
MessageBox.Show(message);
}
注意这里
- select value的value不能省去
- 语句不区分大小写
- 后面的";"可以不存在。