[Entity Framework]
[Entity Framework]获取部分字段的查询
View Code
string entitySQL = "SELECT VALUE u FROM Users AS u WHERE EXISTS(SELECT p FROM Users AS p WHERE p.Roleid = 0);"; var query = ObjectContext.CreateQuery<bool>(entitySQL);
using (var ObjectContext = new AgentSystemEntities()) { DateTime dt = new DateTime(1997, 1, 1); string entitySQL = "SELECT VALUE Users FROM Users WHERE Users.AddDateTime > @dt;"; ObjectParameter[] ps = { new ObjectParameter("dt", dt) }; ObjectQuery<Users> query = ObjectContext.CreateQuery<Users>(entitySQL,ps); string message = "执行的语句:" + query.CommandText + "\n\r"; if (query.Count() > 0) { message += query.First().UserNames + "\n\r"; } else { message += "没有数据\n\r"; } MessageBox.Show(message); }