Ejemplo n.º 1
0
        public void Test1()
        {
            var p = new SinglePerson {
                Name = "abc"
            };

            Assert.AreEqual(0, p.Id);

            DbEntry.Save(p);
            Assert.IsTrue(0 != p.Id);
            var p1 = DbEntry.GetObject <SinglePerson>(p.Id);

            Assert.AreEqual(p.Name, p1.Name);

            p.Name = "xyz";
            DbEntry.Save(p);
            Assert.AreEqual(p.Id, p1.Id);

            p1 = DbEntry.GetObject <SinglePerson>(p.Id);
            Assert.AreEqual("xyz", p1.Name);

            long id = p.Id;

            DbEntry.Delete(p);
            Assert.AreEqual(0, p.Id);
            p1 = DbEntry.GetObject <SinglePerson>(id);
            Assert.IsNull(p1);
        }
Ejemplo n.º 2
0
        public void Test3()
        {
            DbEntry.Delete <Unit>(WhereCondition.EmptyCondition);

            Unit u = DynamicObject.NewObject <Unit>("00001");

            u.Name      = "吨";
            u.CreatedBy = "Jacky";
            u.UpdatedBy = "Admin";

            DbEntry.Save(u);
            var u1 = DbEntry.GetObject <Unit>(u.UnitId);

            Assert.AreEqual(u1.UnitId, u.UnitId);

            u1.Name = "M3";
            DbEntry.Update(u1);

            Unit u2 = DynamicObject.NewObject <Unit>("00002");

            u2.Init("M3", "Admin");
            Assert.AreEqual("M3", u2.Name);
            DbEntry.Save(u2);

            Assert.AreEqual(2, DbEntry.From <Unit>().Where(WhereCondition.EmptyCondition).GetCount());
        }
Ejemplo n.º 3
0
        public void TestTableNameForCrud()
        {
            DbEntry.From <compTableName>().Where(p => p.Name == "tom").Select();
            AssertSql(@"SELECT [Id],[Name] FROM [tom].[test_table] WHERE [Name] = @Name_0;
<Text><60>(@Name_0=tom:String)");

            var c = new compTableName {
                Name = "tom"
            };

            DbEntry.Insert(c);
            AssertSql(@"INSERT INTO [tom].[test_table] ([Name]) VALUES (@Name_0);
SELECT LAST_INSERT_ROWID();
<Text><30>(@Name_0=tom:String)");

            c.Id   = 2;
            c.Name = "jerry";
            DbEntry.Update(c);
            AssertSql(@"UPDATE [tom].[test_table] SET [Name]=@Name_0  WHERE [Id] = @Id_1;
<Text><30>(@Name_0=jerry:String,@Id_1=2:Int64)");

            DbEntry.Delete(c);
            AssertSql(@"DELETE FROM [tom].[test_table] WHERE [Id] = @Id_0;
<Text><30>(@Id_0=2:Int64)");
        }
Ejemplo n.º 4
0
        public void TestHasOne8()
        {
            // B.Delete will delete itself
            var p = DbEntry.GetObject <Person>(2);

            Assert.IsNotNull(p);
            Assert.IsNotNull(p.PC.Value);
            DbEntry.Delete(p.PC.Value);
            p = DbEntry.GetObject <Person>(2);
            Assert.IsNotNull(p);
            Assert.IsNull(p.PC.Value);
        }
Ejemplo n.º 5
0
        public void Test5()
        {
            // A.Delete will delete A, and delete all the related items in A_B
            var a = DbEntry.GetObject <Article>(1);

            DbEntry.Delete(a);

            a = DbEntry.GetObject <Article>(1);
            Assert.IsNull(a);

            List <Article_Reader> ar = DbEntry.From <Article_Reader>().Where(CK.K["Article_Id"] == 1).Select();

            Assert.AreEqual(0, ar.Count);
        }
Ejemplo n.º 6
0
        public void TestHasMany8()
        {
            // B.Delete will delete itself
            var c = DbEntry.GetObject <Category>(2);

            Assert.IsNotNull(c);
            Assert.IsTrue(3 == c.Books.Count);
            Book b = c.Books[0];

            DbEntry.Delete(b);
            Assert.IsTrue(0 == b.Id);
            c = DbEntry.GetObject <Category>(2);
            Assert.IsNotNull(c);
            Assert.IsTrue(2 == c.Books.Count);
        }
Ejemplo n.º 7
0
        public virtual int ExecuteDelete(T obj)
        {
            if (obj != null)
            {
                var o = obj as DbObjectSmartUpdate;
                if (o != null)
                {
                    o.Delete();
                }
                else
                {
                    DbEntry.Delete(obj);
                }

                return(1);
            }
            return(0);
        }
Ejemplo n.º 8
0
        public virtual string Destroy(long n)
        {
            IDbObject o = DbEntry.GetObject <T>(n);

            if (o != null)
            {
                if (o is DbObjectSmartUpdate)
                {
                    (o as DbObjectSmartUpdate).Delete();
                }
                else
                {
                    DbEntry.Delete(o);
                }
                return(UrlTo().Action("list"));
            }
            return(null);
        }
Ejemplo n.º 9
0
        public void TestPropertyClassWithDbColumn()
        {
            var o = new PropertyClassWithDbColumn {
                TheName = "OK"
            };

            // create
            DbEntry.Save(o);
            // read
            var o1 = DbEntry.GetObject <PropertyClassWithDbColumn>(o.Id);

            Assert.AreEqual("OK", o1.TheName);
            // update
            o1.TheName = "CANCEL";
            DbEntry.Save(o1);
            Assert.AreEqual("CANCEL", DbEntry.GetObject <PropertyClassWithDbColumn>(o.Id).TheName);
            // delete
            DbEntry.Delete(o);
            Assert.IsNull(DbEntry.GetObject <PropertyClassWithDbColumn>(o1.Id));
        }
Ejemplo n.º 10
0
        public void TestPropertyClassBaseCrud()
        {
            var o = new PropertyClassBase {
                Name = "OK"
            };

            // create
            DbEntry.Save(o);
            // read
            var o1 = DbEntry.GetObject <PropertyClassBase>(o.Id);

            Assert.AreEqual("OK", o1.Name);
            // update
            o1.Name = "CANCEL";
            DbEntry.Save(o1);
            Assert.AreEqual("CANCEL", DbEntry.GetObject <PropertyClassBase>(o.Id).Name);
            // delete
            DbEntry.Delete(o);
            Assert.IsNull(DbEntry.GetObject <PropertyClassBase>(o1.Id));
        }
Ejemplo n.º 11
0
        public virtual int ExecuteDelete(T obj)
        {
            if (obj != null)
            {
                RaiseEvent(ObjectDeleting, obj);

                var o = obj as DbObjectSmartUpdate;
                if (o != null)
                {
                    o.Delete();
                }
                else
                {
                    DbEntry.Delete(obj);
                }

                RaiseEvent(ObjectDeleted, obj);
                return(1);
            }
            return(0);
        }
Ejemplo n.º 12
0
        public void Test1()
        {
            Role role = Role.New();

            role.Name      = "Jacky";
            role.CreatedBy = "Jacky";
            role.UpdatedBy = "Jacky";
            DbEntry.Save(role);

            var r = DbEntry.GetObject <Role>(role.Id);

            Assert.AreEqual(role.Name, r.Name);

            role.Name = "Niuniu";
            DbEntry.Save(role);
            Assert.AreEqual(role.Id, r.Id);

            long id = r.Id;

            DbEntry.Delete(role);
            var r1 = DbEntry.GetObject <Role>(id);

            Assert.IsNull(r1);
        }