コード例 #1
0
        public static void DeleteShouldDeleteChildren()
        {
            SqlClientRegistrar.Register <DaoReferenceObject>();

            DaoReferenceObject parent = new DaoReferenceObject();

            parent.StringProperty = "Parent_".RandomString(3);

            parent.Commit();

            var d1 = parent.DaoReferenceObjectWithForeignKeyCollectionByDaoReferenceObjectId.AddNew();

            d1.Name = "".RandomString(3);

            var d2 = parent.DaoReferenceObjectWithForeignKeyCollectionByDaoReferenceObjectId.AddNew();

            d2.Name = "".RandomString(3);

            parent.Commit();

            Expect.IsNotNull(d2.Id);

            DaoReferenceObject check = DaoReferenceObject.OneWhere(c => c.Id == parent.Id);
            DaoReferenceObjectWithForeignKey check2 = DaoReferenceObjectWithForeignKey.OneWhere(c => c.Id == d2.Id);

            Expect.AreEqual(2, check.DaoReferenceObjectWithForeignKeyCollectionByDaoReferenceObjectId.Count);
            Expect.IsNotNull(check2);

            check.Delete();

            check2 = DaoReferenceObjectWithForeignKey.OneWhere(c => c.Id == d2.Id);
            Expect.IsNull(check2);
        }
コード例 #2
0
        public static void DeleteShouldWork()
        {
            SqlClientRegistrar.Register(Db.For <DaoReferenceObject>().ServiceProvider);

            DaoReferenceObject test = new DaoReferenceObject();

            test.StringProperty = "".RandomString(8);
            test.Commit();

            DaoReferenceObject d = DaoReferenceObject.OneWhere(c => c.Id == test.Id);

            Expect.IsNotNull(d);
            Expect.AreEqual(test.StringProperty, d.StringProperty);

            d.Delete();

            d = DaoReferenceObject.OneWhere(c => c.StringProperty == test.StringProperty);
            Expect.IsNull(d);
        }