示例#1
0
        public _002_Explicit()
        {
            using (var db = new TrainintDBContext())
            {
                var doc = db.UserDocument.FirstOrDefault();
                db.Entry(doc).Reference("User").Load();

                if (doc.User != null)
                {
                    Console.WriteLine(doc.Id);
                }
            }
        }
示例#2
0
        public _002_OneToMany()
        {
            this.Init();

            using (var db = new TrainintDBContext())
            {
                var users = db.Users.Include("Documents").ToList();
                PrintConsole(users);

                var userFirst = users.FirstOrDefault();
                userFirst.Name = "Test";
                userFirst.Age  = 100;

                db.Entry(userFirst).State = EntityState.Modified;
                db.SaveChanges();

                PrintConsole(db.Users.Include("Documents").ToList());
            }
        }