示例#1
0
        public void Indexing2()
        {
            var db = new DbInstance(@"MyDatabase2\Indexing");

            db.Map <IData, InterfaceBasedData>().Automap(i => i.Id, true)
            .WithIndex("LastName", i => i.Name, StringComparer.CurrentCulture)
            .WithIndex("LastNameText", i => i.Name, StringComparer.CurrentCultureIgnoreCase);
            db.Initialize();

            var table = db.Table <IData>();

            table.Purge();

            db.BulkWrite(() =>
            {
                for (var s = 0; s < 100; s++)
                {
                    for (var i = 0; i < 10; i++)
                    {
                        table.Save(new InterfaceBasedData {
                            Name = "Test" + i
                        });
                    }
                }

                for (var s = 0; s < 100; s++)
                {
                    for (var i = 0; i < 10; i++)
                    {
                        table.Save(new InterfaceBasedData {
                            Name = "TeST" + i
                        });
                    }
                }
            });

            var list1count = table.IndexQuery <string>("LastName").Key("Test5").Count();
            var list2count = table.IndexQuery <string>("LastNameText").Key("TEst5").Count();

            Assert.AreEqual(list1count, 100);
            Assert.AreEqual(list2count, 200);

            var list3count = table.IndexQuery <string>("LastName").GreaterThan("Test5").Count();
            var list4count = table.IndexQuery <string>("LastName").LessThan("Test6").Count();
            var list5count = table.IndexQuery <string>("LastName").LessThan("Test6").GreaterThan("Test5").Count();

            Assert.AreEqual(900, list3count);
            Assert.AreEqual(1200, list4count);
            Assert.AreEqual(100, list5count);

            var list6count = table.IndexQuery <string>("LastName").GreaterThan("Test5", true).Count();
            var list7count = table.IndexQuery <string>("LastName").LessThan("Test6", true).Count();
            var list8count = table.IndexQuery <string>("LastName").LessThan("Test6", true).GreaterThan("Test5", true).Count();

            Assert.AreEqual(1000, list6count);
            Assert.AreEqual(1300, list7count);
            Assert.AreEqual(300, list8count);
        }
示例#2
0
        public void SaveData()
        {
            var swatch = DateTime.Now;

            db.BulkWrite(() =>
            {
                table.Purge();
                var key    = 1;
                var newObj = new MyData {
                    Id = key, Name = "test"
                };
                table.Save(newObj);

                var obj = table.LoadByKey(key);

                Assert.AreEqual(newObj.Name, obj.Name);
#if !(NETFX_CORE || WINDOWS_PHONE)
                TestContext.WriteLine("Completed: " + (DateTime.Now - swatch).TotalMilliseconds);
#endif
            });
        }
示例#3
0
        public void Indexing3()
        {
            var db = new DbInstance(@"MyDatabase3\Indexing");

            db.Map <AData, PrototypeBasedData>().Automap(i => i.Id, true)
            .WithIndex("LastName", i => i.Name, StringComparer.CurrentCulture)
            .WithIndex("LastNameText", i => i.Name, StringComparer.CurrentCultureIgnoreCase);
            db.Initialize();

            var table = db.Table <AData>();

            table.Purge();

            db.BulkWrite(() =>
            {
                for (var s = 0; s < 100; s++)
                {
                    for (var i = 0; i < 10; i++)
                    {
                        table.Save(new PrototypeBasedData {
                            Name = "Test" + i
                        });
                    }
                }

                for (var s = 0; s < 100; s++)
                {
                    for (var i = 0; i < 10; i++)
                    {
                        table.Save(new PrototypeBasedData {
                            Name = "TeST" + i
                        });
                    }
                }
            });

            var list1count = table.IndexQueryByKey("LastName", "Test5").Count();
            var list2count = table.IndexQueryByKey("LastNameText", "TEst5").Count();

            Assert.AreEqual(list1count, 100);
            Assert.AreEqual(list2count, 200);
        }
示例#4
0
        public void IndexingDetails()
        {
            var db = new DbInstance(@"My Database\Indexing2");

            db.Map <MyData>().Automap(i => i.Id, true).WithIndex("Test", i => i.IntField);
            db.Initialize();

            var table = db.Table <MyData>();

            table.Purge();

            db.BulkWrite(() =>
            {
                table.Save(new MyData {
                    IntField = 1
                });
                table.Save(new MyData {
                    IntField = 1
                });
                table.Save(new MyData {
                    IntField = 1
                });
                table.Save(new MyData {
                    IntField = 1
                });
                table.Save(new MyData {
                    IntField = 1
                });
                table.Save(new MyData {
                    IntField = 4
                });
                table.Save(new MyData {
                    IntField = 4
                });
                table.Save(new MyData {
                    IntField = 4
                });
                table.Save(new MyData {
                    IntField = 4
                });
                table.Save(new MyData {
                    IntField = 4
                });
                table.Save(new MyData {
                    IntField = 3
                });
                table.Save(new MyData {
                    IntField = 3
                });
                table.Save(new MyData {
                    IntField = 3
                });
                table.Save(new MyData {
                    IntField = 3
                });
                table.Save(new MyData {
                    IntField = 3
                });
                table.Save(new MyData {
                    IntField = 4
                });
                table.Save(new MyData {
                    IntField = 5
                });
                table.Save(new MyData {
                    IntField = 6
                });
                table.Save(new MyData {
                    IntField = 6
                });
                table.Save(new MyData {
                    IntField = 6
                });
                table.Save(new MyData {
                    IntField = 6
                });
                table.Save(new MyData {
                    IntField = 6
                });
                table.Save(new MyData {
                    IntField = 6
                });
                table.Save(new MyData {
                    IntField = 7
                });
                table.Save(new MyData {
                    IntField = 8
                });
                table.Save(new MyData {
                    IntField = 8
                });
                table.Save(new MyData {
                    IntField = 8
                });
                table.Save(new MyData {
                    IntField = 8
                });
                table.Save(new MyData {
                    IntField = 8
                });
                table.Save(new MyData {
                    IntField = 9
                });
            });

            var list1 = table.LoadAll();

            var index = table.IndexQuery <int>("Test");

            Assert.AreEqual(index.Key(1).Count(), list1.Count(i => i.IntField == 1));
            Assert.AreEqual(index.Key(8).Count(), list1.Count(i => i.IntField == 8));

            Assert.AreEqual(index.GreaterThan(6, true).LessThan(8).Count(), list1.Count(i => i.IntField >= 6 && i.IntField < 8));

            IdSequenceEqual(index.GreaterThan(6).LessThan(8).ToList(), list1.Where(i => i.IntField > 6 && i.IntField < 8));
            IdSequenceEqual(index.LessThan(8).ToList(), list1.Where(i => i.IntField < 8));
            IdSequenceEqual(index.GreaterThan(6, true).ToList(), list1.Where(i => i.IntField >= 6));
            IdSequenceEqual(index.GreaterThan(7, true).LessThan(7).ToList(), list1.Where(i => i.IntField >= 7 && i.IntField < 7));
            IdSequenceEqual(index.GreaterThan(7).LessThan(7, true).ToList(), list1.Where(i => i.IntField > 7 && i.IntField <= 7));
        }
示例#5
0
 /// <summary>
 /// Asynchronously executes write actions inside write transaction
 /// </summary>
 /// <param name="db">Database instance to write to</param>
 /// <param name="writes">Write operations to perform</param>
 /// <returns>Awaitable Task of write operations</returns>
 public static Task BulkWriteAsync(this DbInstance db, Action writes)
 {
     return(TaskEx.Run(() => db.BulkWrite(writes)));
 }