新建Model1.edmx文件
页面引用数据库Model1 如下创建AD数据库的model文件、
找到以下菜单
找到所需要引用数据库类名称。
在页面后台引用
class="brush:csharp;gutter:true;">using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace WebApplication4 { public partial class WebForm1 : System.Web.UI.Page { protected readonly tb_FaceGroup _context; private readonly ADEntities datesql = new ADEntities(); protected void Page_Load(object sender, EventArgs e) { ADEntities db = new ADEntities();//所需要实例化的类 //添加动作 //tb_user dd = new tb_user(); //dd.ID = "ddsds"; //dd.Wid = "dsdssd"; //db.tb_user.Add(dd); //db.SaveChanges();--把以上代码变更到数据库 //查询 // List<tb_user> lstOrder = new List<tb_user>(); tb_user lstOrder = new tb_user(); // lstOrder = datesql.tb_user.GroupBy(r => r.ID == "ddsds"); var info = datesql.tb_user.OrderByDescending(r => r.ID == "ddsds");// .FirstOrDefault(r => r.ID == "ddsds"); //打印查询结果 if (info.Any()) { foreach (var userEntity in info) { Console.WriteLine(userEntity.ID + "----" + userEntity.Wid); } } } } }