方法一:Linq to Entitie var info = from p in entity.Users where p.ID = 10 orderby p.ID descending select p;foreach (var item in info){ Console.WriteLine("ID:" + item.ID + " " + "登录名:" + item.LoginName + " " + "密码:" + item.Pass
方法一:Linq to Entitie
var info = from p in entity.Users where p.ID >= 10 orderby p.ID descending select p; foreach (var item in info) { Console.WriteLine("ID:" + item.ID + " " + "登录名:" + item.LoginName + " " + "密码:" + item.Password); }
方法二:Lamada表达式
var info2 = entity.Users.Where<User>(p => p.ID >= 10).OrderByDescending(p => p.ID); foreach (var item in info) { Console.WriteLine("ID:" + item.ID + " " + "登录名:" + item.LoginName + " " + "密码:" + item.Password); }
方法三:Entity SQL Language
var info3 = ((IObjectContextAdapter)entity).ObjectContext.CreateQuery<User>(strSQL); foreach (var item in info) { Console.WriteLine("ID:" + item.ID + " " + "登录名:" + item.LoginName + " " + "密码:" + item.Password); }
方法四:SqlQuery
try { string strSQL2 = "SELECT * FROM Users WHERE ID>=10 ORDER BY ID DESC"; var info4 = entity.Database.SqlQuery<User>(strSQL2); foreach (var item in info) { Console.WriteLine("ID:" + item.ID + " " + "登录名:" + item.LoginName + " " + "密码:" + item.Password); } } catch (Exception ex) { Console.WriteLine(ex.Message); }
到此这篇关于Entity Framework常用查询语句的文章就介绍到这了。希望对大家的学习有所帮助,也希望大家多多支持自由互联。