Linq To EF 간단한 추가, 삭제, 검색, 수정

1444 단어 StringnullemailLINQ
새로 추가됨
            // 
            T_Teacher tt1 = new T_Teacher()
            {
                Name = " ",
                Address = " 55 ",
                Phone = "13725256545",
                Email = "[email protected]",
                ClassID = 1
            };
            sdb.T_Teacher.AddObject(tt1);
            int result = sdb.SaveChanges();

삭제
            // 
            var ttlist = from cc in sdb.T_Teacher where cc.ID == 3 select cc;
            foreach (var item in ttlist)
            {
                sdb.T_Teacher.DeleteObject(item);
            }
            int result = sdb.SaveChanges();

조회
            // 
            var ttlist = from cc in sdb.T_Teacher select cc;
            string result = "";
            foreach (var item in ttlist)
            {
                result += item.Name + "*******";
            }

수정하다
            // 
            var ttlist = from cc in sdb.T_Teacher select cc;
            var wokao = ttlist.FirstOrDefault<T_Teacher>();
            int result = 0;
            if (wokao != null)
            {
                wokao.Name = "123";
                result = sdb.SaveChanges();
            }
            else
            {
                result = 0;
            }

좋은 웹페이지 즐겨찾기