public void Populate()
        {
            DeleteBase(DbName);

            using (var odb = Open(DbName))
            {
                var atts = new[] {"name"};
                odb.IndexManagerFor<User2>().AddUniqueIndexOn("Index", atts);

                const int nbProfiles = 200;
                const int nbUsers = 500;
                var profiles = new Profile[nbProfiles];
                var users = new User2[nbUsers];
                const int userStart = 1500;
                const int profileStart = 600;

                // First creates profiles
                for (var i = 0; i < nbProfiles; i++)
                {
                    profiles[i] = new Profile("profile " + (i + profileStart),
                                              new VO.Login.Function("function Profile" + i));
                    odb.Store(profiles[i]);
                }

                // Then creates users
                for (var i = 0; i < nbUsers; i++)
                {
                    users[i] = new User2("user" + (i + userStart), "user mail" + i,
                                         profiles[GetProfileIndex(nbProfiles)], i);
                    odb.Store(users[i]);
                    if (i%100 == 0)
                        Println(i);
                }
            }
        }
        public virtual void Populate()
        {
            OdbFactory.Delete(DbName);

            using (var odb = Open(DbName))
            {
                const int nbProfiles = 20;
                const int nbUsers = 50;
                var profiles = new Profile[nbProfiles];
                var users = new User2[nbUsers];

                // First creates profiles
                for (var i = 0; i < nbProfiles; i++)
                {
                    profiles[i] = new Profile("profile " + i, new VO.Login.Function("function Profile" + i));
                    odb.Store(profiles[i]);
                }

                // Then creates users
                for (var i = 0; i < nbUsers; i++)
                {
                    users[i] = new User2("user" + i, "user mail" + i, profiles[GetProfileIndex(nbProfiles)], i);
                    odb.Store(users[i]);
                    if (i%10 == 0)
                        Println(i);
                }
            }
        }
Ejemplo n.º 3
0
        public void Test3()
        {
            DeleteBase(DbName3);
            using (var odb = Open(DbName3))
            {
                var p1 = new Profile("profile1", new VO.Login.Function("f1"));
                var p2 = new Profile("profile2", new VO.Login.Function("f2"));

                User u1 = new User2("user1", "*****@*****.**", p1, 1);
                User u2 = new User2("user2", "*****@*****.**", p1, 2);
                User u3 = new User2("user3", "*****@*****.**", p1, 3);
                User u4 = new User2("user4", "*****@*****.**", p2, 4);
                User u5 = new User2("user5", "*****@*****.**", p2, 5);

                odb.Store(u1);
                odb.Store(u2);
                odb.Store(u3);
                odb.Store(u4);
                odb.Store(u5);
            }

            IValues values;
            using (var odb = Open(DbName3))
            {
                var q =
                    odb.ValuesQuery<User2>().Field("profile.name").Count("count").Avg("nbLogins", "avg").
                        GroupBy("profile.name");

                q.Descend("name").OrderAscending();
                values = q.Execute();
                Println(values);

                var ov = values.NextValues();
                AssertEquals(2, values.Count());
                AssertEquals("profile1", ov.GetByAlias("profile.name"));
                AssertEquals(Convert.ToDecimal("3"), ov.GetByAlias("count"));
                AssertEquals(Convert.ToDecimal("2.00", CultureInfo.InvariantCulture), ov.GetByAlias("avg"));
            }

            AssertEquals(2, values.Count());
        }