public void XOnDeleteCascade()
        {
#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.Equal("Einstein, Albert", s.Name);
                Kardex k = s.Kardexes.First();
                Assert.Equal(9.0, k.Score);
                ctx.DeleteObject(s);
                ctx.SaveChanges();
            }

            using (ModelFirstModel1Container ctx = new ModelFirstModel1Container())
            {
                var q = from st in ctx.Students select st;
                Assert.Equal(0, q.Count());
                var q2 = from k in ctx.Kardexes select k;
                Assert.Equal(0, q2.Count());
            }
        }
Exemplo n.º 2
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());
      }
    }