本文整理汇总了C#中Database.Set方法的典型用法代码示例。如果您正苦于以下问题:C# Database.Set方法的具体用法?C# Database.Set怎么用?C# Database.Set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Database
的用法示例。
在下文中一共展示了Database.Set方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestDatabaseWithLotsOfKeys
public void TestDatabaseWithLotsOfKeys()
{
if (Directory.Exists("testdb")) Directory.Delete("testdb", true);
using (var db = new Database<TestEntry>("testdb", false))
{
for (var i = 0; i < 100000; i++)
{
db.Set(i.ToString(), new TestEntry(Guid.NewGuid().ToString()));
}
Assert.IsNotNull(db.Get("5000"));
Assert.IsNull(db.Get("xxxx"));
Console.WriteLine($"levels : {db.CurrentLevelNumber}");
}
using (var db = new Database<TestEntry>("testdb"))
{
Assert.IsNotNull(db.Get("5000"));
Assert.IsNull(db.Get("xxxx"));
}
if (Directory.Exists("testdb")) Directory.Delete("testdb", true);
}
示例2: SimpleDatabaseTest
public void SimpleDatabaseTest()
{
if (Directory.Exists("testdb")) Directory.Delete("testdb", true);
using (var db = new Database<TestEntry>("testdb"))
{
db.Set("foo", new TestEntry("bar"));
Assert.AreEqual("bar", db.Get("foo").Value);
}
using (var db = new Database<TestEntry>("testdb"))
{
Assert.AreEqual("bar", db.Get("foo").Value);
}
if (Directory.Exists("testdb")) Directory.Delete("testdb", true);
}
示例3: TestDatabaseSearch
public void TestDatabaseSearch()
{
if (Directory.Exists("testdb")) Directory.Delete("testdb", true);
using (var db = new Database<TestEntry>("testdb", false))
{
for (var i = 0; i < 200000; i++)
{
db.Set(i.ToString("D8"), new TestEntry(Guid.NewGuid().ToString()));
}
Console.WriteLine($"levels : {db.CurrentLevelNumber}");
db.Del("00000101");
var results = db.Between("00000100", "00000110").OrderBy(x => x.Key).ToArray();
Assert.AreEqual(9, results.Length);
Assert.AreEqual("00000100", results[0].Key);
Assert.IsFalse(results.Select(x => x.Key).Contains("00000101"));
}
if (Directory.Exists("testdb")) Directory.Delete("testdb", true);
}
示例4: Main
static void Main(string[] args)
{
var rand = new Random();
if (Directory.Exists("saturation")) Directory.Delete("saturation", true);
using (var db = new Database<TestValue2>("saturation"))
{
var timer = Stopwatch.StartNew();
for (var i = 0; i < (1000 * 1000); i++)
{
var kv = i.ToString();
db.Set(kv, new TestValue2 { Value = kv });
if (i % 10000 == 0) Console.WriteLine(i);
}
timer.Stop();
Console.WriteLine($"{timer.ElapsedMilliseconds}");
}
}
示例5: WriteNulls
public void WriteNulls()
{
if (Directory.Exists("testdb")) Directory.Delete("testdb", true);
using (var db = new Database<TestClass>("testdb"))
{
db.Set("foo", null);
Assert.IsNull(db.Get("foo"));
}
using (var db = new Database<TestClass>("testdb"))
{
Assert.IsNull(db.Get("foo"));
}
}
示例6: SimpleDatabaseTestWithPoco
public void SimpleDatabaseTestWithPoco()
{
if (Directory.Exists("testdb")) Directory.Delete("testdb", true);
using (var db = new Database<TestClass>("testdb"))
{
db.Set("foo", new TestClass { Foo = "foo", Bar = 1337, Baz=true, Qux = Math.PI });
Assert.IsNotNull(db.Get("foo"));
}
using (var db = new Database<TestClass>("testdb"))
{
var foo = db.Get("foo");
Assert.AreEqual("foo", foo.Foo);
Assert.AreEqual(1337, foo.Bar);
Assert.IsTrue(foo.Baz);
Assert.AreEqual(Math.PI, foo.Qux);
}
if (Directory.Exists("testdb")) Directory.Delete("testdb", true);
}