当前位置: 首页>>代码示例>>C#>>正文


C# Database.Clear方法代码示例

本文整理汇总了C#中Database.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# Database.Clear方法的具体用法?C# Database.Clear怎么用?C# Database.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Database的用法示例。


在下文中一共展示了Database.Clear方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DatabaseSavesOneHundredThousandRecords

        public void DatabaseSavesOneHundredThousandRecords()
        {
            _testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();

            decimal avgTime = 0;
            var stopWatch = new Stopwatch();

            using (var fLock = new ManagedFileLock(_testName))
            {
                Cleanup();

                using (var db = new Database<int, MockClassA>(_testName + ".database", "Id"))
                {
                    db.Load();

                    stopWatch.Start();
                    using (var t = db.BeginTransaction())
                    {
                        TestResourceFactory.GetMockClassAObjects(25000).ToList().ForEach(a => db.Add(a));

                        t.Commit();
                    }
                    stopWatch.Stop();
                    avgTime = (avgTime + stopWatch.ElapsedMilliseconds);

                    Console.WriteLine("Transaction with 25000 entities committed in {0} seconds", stopWatch.ElapsedMilliseconds / 1000m);

                    stopWatch.Reset();
                    stopWatch.Start();
                    using (var t = db.BeginTransaction())
                    {
                        TestResourceFactory.GetMockClassAObjects(25000).ToList().ForEach(a => db.Add(a));

                        t.Commit();
                    }
                    stopWatch.Stop();
                    avgTime = (avgTime + stopWatch.ElapsedMilliseconds) / 2;

                    Console.WriteLine("Transaction with 25000 entities committed in {0} seconds", stopWatch.ElapsedMilliseconds / 1000m);

                    stopWatch.Reset();
                    stopWatch.Start();
                    using (var t = db.BeginTransaction())
                    {
                        TestResourceFactory.GetMockClassAObjects(25000).ToList().ForEach(a => db.Add(a));

                        t.Commit();
                    }
                    stopWatch.Stop();
                    avgTime = (avgTime + stopWatch.ElapsedMilliseconds) / 2;

                    Console.WriteLine("Transaction with 25000 entities committed in {0} seconds", stopWatch.ElapsedMilliseconds / 1000m);

                    stopWatch.Reset();
                    stopWatch.Start();
                    using (var t = db.BeginTransaction())
                    {
                        TestResourceFactory.GetMockClassAObjects(25000).ToList().ForEach(a => db.Add(a));

                        t.Commit();
                    }
                    stopWatch.Stop();
                    avgTime = (avgTime + stopWatch.ElapsedMilliseconds) / 2;

                    Console.WriteLine("Transaction with 25000 entities committed in {0} seconds", stopWatch.ElapsedMilliseconds / 1000m);

                    Console.WriteLine("Avg Commit time for trans with 25000 entities {0} seconds", avgTime / 1000m);

                    stopWatch.Reset();
                    stopWatch.Start();
                    Assert.AreEqual(20000, db.Select(o => o.Value<int>("Id") > 80000).Count());
                    stopWatch.Stop();

                    Console.WriteLine("query with 20000 records retreived in {0} seconds", stopWatch.ElapsedMilliseconds / 1000m);

                    db.Flush();
                }

                using (var db = new Database<int, MockClassA>(_testName + ".database"))
                {
                    var len = db.Load();

                    Assert.AreEqual(100000, len);

                    stopWatch.Reset();
                    stopWatch.Start();
                    Assert.AreEqual(20000, db.Select(o => o.Value<int>("Id") > 80000).Count());
                    stopWatch.Stop();

                    Console.WriteLine("query with 20000 records retreived in {0} seconds", stopWatch.ElapsedMilliseconds / 1000m);

                    db.Clear();
                }
            }
        }
开发者ID:thehexgod,项目名称:BESSY-DB,代码行数:95,代码来源:DatabaseCapacityTests.cs

示例2: PubSubNeverPicksUpOwnTransactions

        public void PubSubNeverPicksUpOwnTransactions()
        {
            _testName = System.Reflection.MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();

            using (var fLock = new ManagedFileLock(_testName))
            {
                Cleanup();

                using (var pdb1 = new Database<Guid, MockClassA>(_testName + ".subscriber" + ".database", "ReplicationID", new FileCore<Guid, long>())
                    .WithPublishing("Test", new FilePublisher<Guid, MockClassA>(Path.Combine(Environment.CurrentDirectory, _testName)))
                    .WithSubscription("Test", new FileSubscriber<Guid, MockClassA>(Path.Combine(Environment.CurrentDirectory, _testName), new TimeSpan(0, 0, 0, 0, 500))))
                {
                    pdb1.Load();
                    pdb1.Clear();

                    using (var t = pdb1.BeginTransaction())
                    {
                        pdb1.Delete(o => o != null);

                        t.Commit();
                    }

                    Assert.IsTrue(Directory.Exists(Path.Combine(Environment.CurrentDirectory, _testName)));

                    var objects = TestResourceFactory.GetMockClassAObjects(25).OfType<MockClassC>().ToList();
                    var negativeObjects = TestResourceFactory.GetMockClassAObjects(25).OfType<MockClassC>().ToList();

                    using (var t = pdb1.BeginTransaction())
                    {
                        objects.ForEach(o => pdb1.Add(o));

                        t.Commit();
                    }

                    var testTran = new MockTransaction<Guid, MockClassA>(
                        new TransactionManager<Guid, MockClassA>(
                            new MockTransactionFactory<Guid, MockClassA>()
                            , new TransactionSynchronizer<Guid, MockClassA>()));

                    testTran.Source = pdb1.TransactionSource;

                    foreach (var no in negativeObjects)
                        testTran.Enlist(Action.Create, no.ReplicationID, (MockClassA)no);

                    testTran.Commit();

                    var formatter = new BSONFormatter();

                    using (var fs = new FileStream(
                        Path.Combine(Environment.CurrentDirectory, _testName, testTran.Id.ToString() + ".trans")
                        , FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None, 4096, false))
                    {
                        var s = formatter.FormatObjStream(testTran);

                        s.WriteAllTo(fs);

                        fs.Flush();
                        fs.Close();
                    }

                    Thread.Sleep(750);

                    var sw = new Stopwatch();
                    sw.Start();

                    while (pdb1.FileFlushQueueActive && sw.ElapsedMilliseconds < 3000)
                        Thread.Sleep(100);

                    Assert.AreEqual(25, pdb1.Length);
                }
            }
        }
开发者ID:thehexgod,项目名称:BESSY-DB,代码行数:72,代码来源:MultiplePublisherSubscriberTests.cs

示例3: Fill

 public virtual int Fill(Database.MembersDataTable dataTable) {
     this.Adapter.SelectCommand = this.CommandCollection[0];
     if ((this.ClearBeforeFill == true)) {
         dataTable.Clear();
     }
     int returnValue = this.Adapter.Fill(dataTable);
     return returnValue;
 }
开发者ID:TimBarcz,项目名称:groop,代码行数:8,代码来源:Database.Designer.cs

示例4: DatabaseFetchesUpdatesAndDeletesWithSecondaryIndex

        public void DatabaseFetchesUpdatesAndDeletesWithSecondaryIndex()
        {
            _testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();
            Cleanup();

            var seed = new Seed32();
            var objs = TestResourceFactory.GetMockClassAObjects(100).ToList();
            var ids = new List<int>();

            using (var db = new Database<int, MockClassA>(_testName + ".database", "Id", new FileCore<int, long>())
                .WithIndex<string>("catIndex", "CatalogName", new BinConverterString()))
            {
                db.Load();

                objs.ToList().ForEach(o => ids.Add(db.Add(o)));

                db.FlushAll();
            }

            using (var db = new Database<int, MockClassA>(_testName + ".database", "Id")
                .WithIndex<string>("catIndex", "CatalogName", new BinConverterString()))
            {
                db.Load();

                var last = db.Fetch(objs.Last().Id);

                Assert.IsNotNull(last);

                last.Name = "last";

                db.Update(last, last.Id);

                db.FlushAll();
            }

            using (var db = new Database<int, MockClassA>(_testName + ".database", "Id", new FileCore<int, long>())
                .WithIndex<string>("catIndex", "CatalogName", new BinConverterString()))
            {
                db.Load();

                var last = db.Fetch(objs.Last().Id);

                Assert.IsNotNull(last);
                Assert.AreEqual("last", last.Name);

                Assert.IsNotNull(db.Fetch(objs.First().Id));

                db.Delete(objs.First().Id);

                Assert.IsNull(db.Fetch(objs.First().Id));

                db.FlushAll();
            }

            using (var db = new Database<int, MockClassA>(_testName + ".database", "Id", new FileCore<int, long>())
                .WithIndex<string>("catIndex", "CatalogName", new BinConverterString()))
            {
                db.Load();

                Assert.IsNull(db.Fetch(objs.First().Id));

                db.Clear();
            }
        }
开发者ID:thehexgod,项目名称:BESSY-DB,代码行数:64,代码来源:SecondaryIndexTests.cs

示例5: DatabaseUpdatesIdFieldAndIndexes

        public void DatabaseUpdatesIdFieldAndIndexes()
        {
            _testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();

            var objs = TestResourceFactory.GetMockClassAObjects(100).ToList();
            var ids = new List<int>();

            using (var fLock = new ManagedFileLock(_testName))
            {
                Cleanup();
                using (var db = new Database<int, MockClassA>(_testName + ".database", "Id"))
                {
                    db.Load();

                    objs.ToList().ForEach(o => ids.Add(db.Add(o)));

                    db.FlushAll();
                }

                using (var db = new Database<int, MockClassA>(_testName + ".database"))
                {
                    db.Load();

                    var last = db.Fetch(objs.Last().Id);

                    Assert.IsNotNull(last);

                    var oldId = last.Id;
                    last.Name = "last";
                    last.Id = 1024;

                    db.Update(last, oldId);

                    last = db.Fetch(last.Id);

                    Assert.AreEqual(1024, last.Id);

                    var old = db.Fetch(oldId);

                    Assert.IsNull(old);

                    db.FlushAll();
                }

                using (var db = new Database<int, MockClassA>(_testName + ".database", "Id"))
                {
                    db.Load();

                    var last = db.Fetch(objs.Last().Id);
                    Assert.IsNull(last);

                    last = db.Fetch(1024);
                    Assert.IsNotNull(last);

                    Assert.AreEqual("last", last.Name);

                    Assert.IsNotNull(db.Fetch(objs.First().Id));

                    db.Delete(new int[] { objs.First().Id, objs.Last().Id });

                    Assert.IsNull(db.Fetch(objs.First().Id));
                    Assert.IsNull(db.Fetch(objs.Last().Id));

                    db.FlushAll();
                }

                using (var db = new Database<int, MockClassA>(_testName + ".database", "Id"))
                {
                    db.Load();

                    Assert.IsNull(db.Fetch(objs.First().Id));

                    db.Clear();
                }
            }
        }
开发者ID:thehexgod,项目名称:BESSY-DB,代码行数:76,代码来源:DatabaseCRUDTests.cs

示例6: DatabaseFetchesUpdatesAndDeletes

        public void DatabaseFetchesUpdatesAndDeletes()
        {
            _testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();

            var objs = TestResourceFactory.GetMockClassAObjects(100).ToList();

            using (var fLock = new ManagedFileLock(_testName))
            {
                Cleanup();

                using (var db = new Database<int, MockClassA>(_testName + ".database", "Id"))
                {
                    db.Load();

                    objs.ToList().ForEach(o => o.Id = db.Add(o));

                    db.FlushAll();
                }

                using (var db = new Database<int, MockClassA>(_testName + ".database"))
                {
                    db.Load();

                    var last = db.Fetch(objs.Last().Id);

                    Assert.IsNotNull(last);

                    last.Name = "last";

                    db.Update(last);

                    db.FlushAll();
                }

                using (var db = new Database<int, MockClassA>(_testName + ".database", "Id"))
                {
                    db.Load();

                    var last = db.Fetch(objs.Last().Id);

                    Assert.IsNotNull(last);
                    Assert.AreEqual("last", last.Name);

                    Assert.IsNotNull(db.Fetch(objs.First().Id));

                    db.Delete(objs.First().Id);

                    Assert.IsNull(db.Fetch(objs.First().Id));

                    db.FlushAll();
                }

                using (var db = new Database<int, MockClassA>(_testName + ".database", "Id"))
                {
                    db.Load();

                    Assert.IsNull(db.Fetch(objs.First().Id));

                    db.Clear();
                }
            }
        }
开发者ID:thehexgod,项目名称:BESSY-DB,代码行数:62,代码来源:DatabaseCRUDTests.cs


注:本文中的Database.Clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。