public void TestUpdateSubclass()
        {
            using (ISession s = Session)
            {
                Class c = InitClasses();
                s.Save(c);
                s.Flush();
            }

            ISession session = Session;
            using (ITransaction tran = session.BeginTransaction())
            {
                try
                {
                    Class c1 = session.CreateCriteria<Class>().List<Class>()[0];
                    session.Save(c1);
                    c1.ClassName = "Test1";
                    var student = new Student {Birthday = DateTime.Now, Class = c1, Gender = Gender.Male};
                    c1.Students.Add(student);

                    var c = new Course { CourseName = "Course1" };
                    session.Save(c);
                    session.Flush();
                    student.Name = "zzzz";

                    session.SaveOrUpdate(c1);
                    tran.Commit();
                }
                catch
                {
                    tran.Rollback();
                }
            }
        }
Esempio n. 2
0
 public void TestDeleteMany2Many()
 {
     Student s=new Student(){Birthday = DateTime.Today,Gender = Gender.Male,Name = "测试3"};
     Course c=new Course(){CourseName = "英语"};
     s.Courses.Add(c);
     //c.Students.Add(s);
     Session.SaveOrUpdate(s);
     Session.Flush();
     s.Courses.Clear();
     Session.SaveOrUpdate(s);
     Session.Flush();
 }