Esempio n. 1
0
        public void QueryTest2()
        {
            var db    = DatabaseHelper.GetHelper("test");
            var repos = new RepositoryDatabase <UserProfile>(db);

            var obj1 = repos.Get(1);
            var obj2 = repos.Get(x => x.Email == "*****@*****.**" && x.Sex == 1);

            var list1 = repos.GroupbyCount <int>(x => x.Sex, x => x.Id > 1 && x.Id < 1000);

            var list2 = repos.GroupbyMax <int, int>(x => x.Sex, x => x.Id, x => x.Id > 1 && x.Id < 1000);

            var list3 = repos.GroupbySum <int, int>(x => x.Sex, x => x.Id, x => x.Id > 1 && x.Id < 1000);

            var sumValue = repos.Sum <int>(x => x.Id, x => x.Id > 1 && x.Id < 1000 && x.Sex == 1);

            var maxValue = repos.Max <int>(x => x.Id, x => x.Id > 1 && x.Id < 1000 && x.Sex == 1);
        }
Esempio n. 2
0
        public void IsnertTest()
        {
            var db          = DatabaseHelper.GetHelper("test");
            var repos       = new RepositoryDatabase <UserProfile>(db);
            var userprofile = Map.Create <UserProfile>();

            /*
             * Map.Create<UserProfile>()创建一个实体对象,与 new UserProfile()类似。
             * 但它们不同在于,Map.Create<UserProfile>()创建的对象可以探测到只赋值过的属性
             */
            userprofile.Name     = "test";
            userprofile.Email    = "*****@*****.**";
            userprofile.FixPhone = "860108888888";
            userprofile.Sex      = 1;
            repos.Insert(userprofile);

            var insertedUser = repos.Get(userprofile.Id);

            Assert.IsNotNull(insertedUser);
            Assert.AreEqual(userprofile.Id, insertedUser.Id);
            Assert.AreEqual(userprofile.Name, insertedUser.Name);
            Assert.AreEqual(userprofile.Email, insertedUser.Email);
            Assert.AreEqual(userprofile.FixPhone, insertedUser.FixPhone);
        }