分类:
MVC
//数据库 use oa go create table UserInfos ( id int identity Primary key, username varchar(64), Number varchar(64), userclass varchar(64), state varchar(64), userparent int ) create table Users ( id int identity Primary key, fathername varchar(64), Number varchar(64), ) UserInfos 的userparent 和Users 的 id 相关 public ActionResult Index() { //join查询方式一 oaEntities1 oa = new oaEntities1(); List<UserJoininfo> info = oa.Database.SqlQuery<UserJoininfo>("select UserInfos.id,UserInfos.username,Users.fathername from UserInfos join Users on UserInfos.userparent=Users.id").ToList(); //join查询方式二linq var joininfo = from u in oa.UserInfos join p in oa.Users on u.userparent equals p.id select new { u.id, u.username, p.fathername }; //join查询方式三lamdba var Joininfod = oa.UserInfos.Join(oa.Users, a => a.userparent, b => b.id, (a, b) => new { a.id, a.username, b.fathername }).ToList(); return View(); }
评价