FrameWork EF的使用
创建ef链接数据库的方式后,会出现一个继承: DbContext的类;
在需要调用数据库的地方new一个Model1类,然后用莱姆达表达式查询或者修改,删除!!!!
莱姆达表达式: 一、查询: 1、单行:var userLogin = db.T_UserLogin.Where(d => d.LoginID == loginID).FirstOrDefault(); 2、多行:1)var list = db.Users.Where(u => u.uName == "刘德华").ToList(); 2)List<User> list = db.Users.Where(u => u.uName == "刘德华").ToList(); 3、连接查询:1)linq连接查询: from a in db.User join b in db.UsersAddresses on a.Id equals b.udid 2)拉姆达表达式连接查询:IQueryable<UsersAddress> addrs = db.User.Include("UsersAddresses").Where(a => a.Id == 1); 3)另一种连接查询:var list = db.User.Join(db.UsersAddresses, c => c.Id, g => g.udid, (c, g) => new { Name = c.Name, GroupName = g.GroupName });