EF 테이블 공동 질의join

1993 단어
시계가 두 장 있어요. m.Dept、m_User, 공동 질의
linq 모드, EF 모드
 
        private void Add()
        {
           List<m_Dept> lst = new List<m_Dept>{
           new m_Dept { DName = "  ", ID = "1" },
           new m_Dept { DName = "  ", ID = "2" },
           new m_Dept { DName = "  ", ID = "3" }
           };

           List<m_User> lstU = new List<m_User>{
           new m_User { UName = "  ", ID = "1"  , DeptID="1"},
           new m_User { UName = "  ", ID = "2" , DeptID="2"},
           new m_User { UName = "  ", ID = "3" , DeptID="1"}
           };

            using(TESTEntities db=new TESTEntities())
            {
                db.m_Dept.AddRange(lst);
                db.m_User.AddRange(lstU);
                db.SaveChanges();
            }
            
        }
        private void getlist()
        {
            using (TESTEntities db = new TESTEntities())
            {

                //linq
                var query = from a in db.m_Dept
                            join b in db.m_User
                            on a.ID equals b.DeptID
                            select new
                            {
                                deptname = a.DName,
                                username = b.UName
                            };
                //ef
                var query2 = db.m_Dept.Join(db.m_User, a => a.ID, b => b.DeptID, (a, b) => new
                    {
                        deptname = a.DName,
                        username = b.UName
                    });

            }

        }

  
 
 
 
 
.

좋은 웹페이지 즐겨찾기