Пример #1
0
        public void OnDeleteCascade()
        {
            #if CLR4
              using (ModelFirstModel1Container ctx = new ModelFirstModel1Container())
              {
            if (ctx.DatabaseExists())
              ctx.DeleteDatabase();
            ctx.CreateDatabase();
            ctx.SaveChanges();
              }
            #endif
              using (ModelFirstModel1Container ctx = new ModelFirstModel1Container())
              {
            Student s = new Student();
            s.Name = "Einstein, Albert";
            s.Kardexes.Add(new Kardex() { Score = 9.0 });
            ctx.AddToStudents(s);
            ctx.SaveChanges();
              }

              using (ModelFirstModel1Container ctx = new ModelFirstModel1Container())
              {
            var a = from st in ctx.Students select st;
            Student s = a.First();
            s.Kardexes.Load();
            Assert.AreEqual( "Einstein, Albert", s.Name );
            Kardex k = s.Kardexes.First();
            Assert.AreEqual(9.0, k.Score);
            ctx.DeleteObject( s );
            ctx.SaveChanges();
              }

              using (ModelFirstModel1Container ctx = new ModelFirstModel1Container())
              {
            var q = from st in ctx.Students select st;
            Assert.AreEqual(0, q.Count());
            var q2 = from k in ctx.Kardexes select k;
            Assert.AreEqual(0, q2.Count());
              }
        }
 /// <summary>
 /// Create a new Student object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 public static Student CreateStudent(global::System.Int32 id, global::System.String name)
 {
     Student student = new Student();
     student.Id = id;
     student.Name = name;
     return student;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Students EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToStudents(Student student)
 {
     base.AddObject("Students", student);
 }