本文整理汇总了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();
}
}
}
示例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);
}
}
}
示例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;
}
示例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();
}
}
示例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();
}
}
}
示例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();
}
}
}