Exemplo n.º 1
0
        private static void UpdateDepartment(ContosoUniversityEntities db)
        {
            var dept = db.Department.Find(InsertedId);

            dept.Name = "John";
            db.SaveChanges();
        }
Exemplo n.º 2
0
 private static void Main(string[] args)
 {
     using (var db = new ContosoUniversityEntities())
     {
         Query(db);
         InsertDepartment(db);
         UpdateDepartment(db);
         RemoveDepartment(db);
     }
 }
Exemplo n.º 3
0
        private static void Query(ContosoUniversityEntities db)
        {
            var data = from p in db.Course select p;

            foreach (var item in data)
            {
                Console.WriteLine(item.CourseID);
                Console.WriteLine(item.Title);
                Console.WriteLine();
            }
        }
Exemplo n.º 4
0
        private static void GetCourse_Git(ContosoUniversityEntities db)
        {
            //var data = db.Course.Where(p => p.Title.Contains("Git")).ToList();
            var data = (from p in db.Course
                        where p.Title.Contains("Git")
                        select p).ToList();

            foreach (var item in data)
            {
                Console.WriteLine(item.Title + "\t" + item.Department.Name);
            }
        }
Exemplo n.º 5
0
        public static void InsertDepartment(ContosoUniversityEntities db)
        {
            var dept = new Department()
            {
                Name      = "Will",
                Budget    = 100,
                StartDate = DateTime.Now
            };

            db.Department.Add(dept);
            db.SaveChanges();

            InsertedId = dept.DepartmentID;
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            using (var db = new ContosoUniversityEntities())
            {
                db.Database.Log = (sql) => { Console.WriteLine(sql); };

                //GetCourse_Git(db);

                var data = (from p in db.Department.Include("Course") select p); //
                foreach (var dept in data)
                {
                    Console.WriteLine(dept.Name);
                    foreach (var course in dept.Course)
                    {
                        Console.WriteLine("\t" + course.Title);
                    }
                }
            }
            Console.ReadLine();
        }
Exemplo n.º 7
0
 private static void RemoveDepartment(ContosoUniversityEntities db)
 {
     db.Department.Remove(db.Department.Find(InsertedId));
     db.SaveChanges();
 }