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


C# Database.Add方法代码示例

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


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

示例1: MultipleThreadsCanSafelyWriteandCommit

		public void MultipleThreadsCanSafelyWriteandCommit()
		{
			var tempPath = Path.GetTempPath();
			var dbPath = Path.Combine(tempPath, "test" + ".ravendb");
			Log("Saving db in: " + dbPath);
			File.Delete(dbPath);
			var persistentSource = new FileBasedPersistentSource(tempPath, "test", writeThrough: true);
			var database = new Database(persistentSource);
			var tableOne = database.Add(new Table("Test1"));
			var tableTwo = database.Add(new Table("Test2"));
			database.Initialize();

			try
			{
				Parallel.For(0, 10, counter =>
				{
					Table table = counter % 2 == 0 ? tableOne : tableTwo;
					ProcessTask(counter, database, table);
				});
			}
			catch (AggregateException aggEx)
			{
				Assert.False(true, aggEx.Message + " : " + aggEx.InnerException.Message);
			}
			finally
			{
				persistentSource.Dispose();
			}
		}
开发者ID:925coder,项目名称:ravendb,代码行数:29,代码来源:MultiThreadedWrites.cs

示例2: It_returns_the_matching_record

            public void It_returns_the_matching_record()
            {
                var db = new Database();
                db.Add(Mock.Of<IRecord>(x => x.FullName == "foo"));
                db.Add(Mock.Of<IRecord>(x => x.FullName == "bar"));

                db.GetByFullName("bar").ShouldNotBeNull();
            }
开发者ID:chinhdo,项目名称:Jump-Location,代码行数:8,代码来源:DatabaseSpec.cs

示例3: It_adds_the_missing_record_to_its_list

            public void It_adds_the_missing_record_to_its_list()
            {
                var db = new Database();
                db.Add(Mock.Of<IRecord>(x => x.FullName == "foo"));
                db.Add(Mock.Of<IRecord>(x => x.FullName == "bar"));

                db.GetByFullName("foo::bar");
                db.Records.Count().ShouldEqual(3);
            }
开发者ID:chinhdo,项目名称:Jump-Location,代码行数:9,代码来源:DatabaseSpec.cs

示例4: It_creates_a_record_when_missing

            public void It_creates_a_record_when_missing()
            {
                var db = new Database();
                db.Add(Mock.Of<IRecord>(x => x.FullName == "foo"));
                db.Add(Mock.Of<IRecord>(x => x.FullName == "bar"));

                var baz = db.GetByFullName("foo::bar");
                baz.ShouldNotBeNull();
                baz.ShouldBeType<Record>();
            }
开发者ID:chinhdo,项目名称:Jump-Location,代码行数:10,代码来源:DatabaseSpec.cs

示例5: OpenDictionary

        protected void OpenDictionary()
        {
            persistentSource = new FileBasedPersistentSource(Path.GetTempPath(), "test_",  writeThrough: false);
            Database = new Database(persistentSource);

            tableOne = Database.Add(new Table("Test1"));
            tableTwo = Database.Add(new Table("Test2"));

            Database.Initialze();
            Database.BeginTransaction();
        }
开发者ID:nieve,项目名称:ravenmq,代码行数:11,代码来源:MultiDicInSingleFile.cs

示例6: SelectExpressionReturnsItems

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

            var objs = TestResourceFactory.GetMockClassAObjects(100).ToList();
            var first = objs.FirstOrDefault() as MockClassC;

            var select = new WhereExpression(
                new CompareToken("ReferenceCode", CompareEnum.Like, first.ReferenceCode),
                new CompareToken("Location.X", CompareEnum.Equals, first.Location.X),
                new CompareToken("Name", CompareEnum.Like, first.Name.Substring(1, first.Name.Length - 2)));

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

                db.Load();

                using (var t = db.BeginTransaction())
                {
                    objs.ToList().ForEach(o => o.Id = db.Add(o));

                    t.Commit();

                    var results = eval.ExecuteSelect(select);

                    Assert.AreEqual(1, results.Count);

                    MockClassC.Validate(results[0].ToObject<MockClassC>(), objs.FirstOrDefault() as MockClassC);
                }
            }
        }
开发者ID:thehexgod,项目名称:BESSY-DB,代码行数:33,代码来源:ExpressionResolverSelectTests.cs

示例7: SelectExpressionReturnsFirstItems

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

            var objs = TestResourceFactory.GetMockClassAObjects(100).ToList();
            var max = objs.Cast<MockClassC>().Max(o => o.Location.X);
            var min = objs.Cast<MockClassC>().Min(o => o.Location.X);

            var first = objs.FirstOrDefault() as MockClassC;

            var select = new WhereExpression(10, true, new CompareToken("Location.X", CompareEnum.Greater, max - min));

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

                db.Load();

                using (var t = db.BeginTransaction())
                {
                    objs.ToList().ForEach(o => o.Id = db.Add(o));

                    t.Commit();

                    var results = eval.ExecuteSelect(select);

                    Assert.LessOrEqual(results.Count, 10);

                    foreach (var result in results)
                        MockClassC.Validate(result.ToObject<MockClassC>(), objs.FirstOrDefault(o => o.Id == result.Value<int>("Id")) as MockClassC);
                }
            }
        }
开发者ID:thehexgod,项目名称:BESSY-DB,代码行数:34,代码来源:ExpressionResolverSelectTests.cs

示例8: OpenDictionary

		protected void OpenDictionary()
		{
			PersistentSource = new FileBasedPersistentSource(tempPath, "test", writeThrough: true);
			database = new Database(PersistentSource);
			Table = database.Add(new Table("Test"));
			database.Initialize();
			database.BeginTransaction();
		}
开发者ID:925coder,项目名称:ravendb,代码行数:8,代码来源:SimpleFileTest.cs

示例9: Populate

 public static Documents Populate(Database database, params string[] names)
 {
     Documents documents = new Documents(new List<string>(names), new List<string>());
     foreach (string name in names)
     {
         string content = GenerateXmlContent(name);
         documents.Content.Add(content);
         database.Add(name, content);
     }
     return documents;
 }
开发者ID:daveaglick,项目名称:Nxdb,代码行数:11,代码来源:Common.cs

示例10: UpdateFromQuery

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

            var objs = TestResourceFactory.GetMockClassAObjects(100).ToList();
            objs.OfType<MockClassC>().ToList().ForEach(o => o.ReferenceCode = null);

            var first = objs.FirstOrDefault() as MockClassC;
            var refCode =  "R " + new Random().Next();

            var select = new ScalarSelectExpression(
                new string[] { "Location.Y" },
                new CompareToken("Id", CompareEnum.Equals, 1),
                new CompareToken("Location.X", CompareEnum.Equals, first.Location.X),
                new CompareToken("Name", CompareEnum.Like, first.Name.Substring(1, first.Name.Length - 2)));

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

                db.Load();

                using (var t = db.BeginTransaction())
                {
                    objs.ToList().ForEach(o => o.Id = db.Add(o));

                    t.Commit();
                }

                using (var t = db.BeginTransaction())
                {
                    var count = eval.ExecuteUpdate(
                        new UpdateExpression(
                            typeof(MockClassC).AssemblyQualifiedName,
                            select,
                            new UpdateToken("Location.Y", 133.33, ValueEnum.Float),
                            new UpdateToken("Location.Z", 222.11, ValueEnum.Float),
                            new UpdateToken("ReferenceCode", refCode)));

                    Assert.AreEqual(1, count);

                    t.Commit();

                    var results = eval.ExecuteScaler(select);

                    Assert.AreEqual(1, results.Count);

                    Assert.AreEqual(133.33f, ((MockClassC)db.Fetch(1)).Location.Y);
                    Assert.AreEqual(222.11f, ((MockClassC)db.Fetch(1)).Location.Z);
                    Assert.AreEqual(refCode, ((MockClassC)db.Fetch(1)).ReferenceCode);
                }
            }
        }
开发者ID:thehexgod,项目名称:BESSY-DB,代码行数:54,代码来源:ExpressionResolverUpdateScalarTests.cs

示例11: DatabaseDeletesFirstLastWithActiveTransactions

        public void DatabaseDeletesFirstLastWithActiveTransactions()
        {
            _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", new FileCore<int, long>(), new BinConverter32(), new JSONFormatter()))
                {
                    db.Load();

                    var t = db.BeginTransaction();

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

                    var last = db.SelectLast(s => true, 1).LastOrDefault();

                    Assert.IsNotNull(last);

                    var count = db.Update(s => s.Value<string>("Name") == last.Name
                        , new System.Action<MockClassA>(a => a.Name = "last"));

                    Assert.AreEqual(1, count);

                    var selected = db.Select(s => true);

                    Assert.AreEqual(100, selected.Count);

                    count = db.DeleteFirst(s => true, 10);

                    Assert.AreEqual(10, count);

                    selected = db.Select(s => true);

                    Assert.AreEqual(90, selected.Count);

                    count = db.DeleteLast(s => true, 10);

                    Assert.AreEqual(10, count);

                    selected = db.Select(s => true);

                    Assert.AreEqual(80, selected.Count);

                    t.Rollback();

                }
            }
        }
开发者ID:thehexgod,项目名称:BESSY-DB,代码行数:53,代码来源:DatabaseQueryTests.cs

示例12: PublisherQueuesTransactionsOnPause

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

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

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

                    db.Add(TestResourceFactory.CreateRandom());

                    db.FlushAll();
                }

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

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

                    using (var fs = File.Create(Path.Combine(Environment.CurrentDirectory, _testName, "test.pause")))
                    {
                        fs.Flush();
                    }

                    using (var tran = db.BeginTransaction())
                    {
                        TestResourceFactory.GetMockClassAObjects(25).ToList().ForEach(m => db.Add(m));

                        tran.Commit();
                    }

                    Thread.Sleep(100);

                    Assert.AreEqual(0, Directory.GetFiles(Path.Combine(Environment.CurrentDirectory, _testName), "*.trans").Count());

                    File.Delete(Path.Combine(Environment.CurrentDirectory, _testName, "test.pause"));

                    Thread.Sleep(3000);

                    Assert.Greater(Directory.GetFiles(Path.Combine(Environment.CurrentDirectory, _testName), "*.trans").Count(), 0);

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

示例13: SubscriberPicksUpTransaction

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

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

                using (var pdb = new Database<Guid, MockClassA>(_testName + ".publisher" + ".database", "ReplicationID")
                    .WithPublishing("Test", new FilePublisher<Guid, MockClassA>(Path.Combine(Environment.CurrentDirectory, _testName))))
                {
                    pdb.Load();

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

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

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

                        var objects = TestResourceFactory.GetMockClassAObjects(25).OfType<MockClassC>().ToList();
                        //objects.ForEach(o => o.ReplicationID = Guid.Empty);

                        using (var tran = pdb.BeginTransaction())
                        {
                            objects.ForEach(o => o.ReplicationID = pdb.Add(o));

                            tran.Commit();
                        }

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

                        while (sdb.Fetch(objects.First().ReplicationID) == null && sw.ElapsedMilliseconds < 6000)
                            Thread.Sleep(750);

                        Assert.IsNotNull(sdb.Fetch(objects.First().ReplicationID));

                        sdb.Flush();
                    }

                    pdb.Flush();
                }
            }
        }
开发者ID:thehexgod,项目名称:BESSY-DB,代码行数:47,代码来源:SubscriberTests.cs

示例14: TcpListenerRecivesPublisher

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

            var random = new Random((int)(DateTime.Now.Ticks / 7335));

            var port = random.Next(8355, 10000);

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

                using (var pdb = new Database<int, MockClassA>(_testName + ".database", "Id")
                    .WithPublishing("Test", new TcpTransactionPublisher<int, MockClassA>(IPAddress.Parse("127.0.0.1"), port, 1, new TcpSettings())))
                {
                    pdb.Load();

                    using (var sdb = new Database<int, MockClassA>(_testName + ".subscriber" + ".database", "Id")
                        .WithSubscription("Test", new TcpTransactionSubscriber<int, MockClassA>(port)))
                    {
                        sdb.Load();

                        var obj = TestResourceFactory.CreateRandom();

                        using (var t = pdb.BeginTransaction())
                        {
                            obj.Id = pdb.Add(obj);

                            t.Commit();
                        }

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

                        while (sdb.Fetch(obj.Id) == null && sw.ElapsedMilliseconds < 2000)
                            Thread.Sleep(100);

                        Assert.IsNotNull(sdb.Fetch(obj.Id));

                        sdb.Flush();
                    }

                    pdb.Flush();
                }
            }
        }
开发者ID:thehexgod,项目名称:BESSY-DB,代码行数:46,代码来源:TcpTests.cs

示例15: DeletesFromQuery

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

            var objs = TestResourceFactory.GetMockClassAObjects(100).ToList();
            var first = objs.FirstOrDefault() as MockClassC;

            var delete = new DeleteExpression(
                new CompareToken("ReferenceCode", CompareEnum.Like, first.ReferenceCode.Substring(1, first.ReferenceCode.Length - 2)),
                new CompareToken("ReferenceCode", CompareEnum.Equals, first.ReferenceCode),
                new CompareToken("ReferenceCode", CompareEnum.NotEquals, first.Name),
                new CompareToken("ReferenceCode", CompareEnum.NotEquals, null),
                new CompareToken("Name", CompareEnum.Greater, "Z" + first.Name),
                new CompareToken("Name", CompareEnum.GreaterOrEqual, first.Name),
                new CompareToken("Name", CompareEnum.Lesser, "A" + first.Name.Substring(1, first.Name.Length - 1)),
                new CompareToken("Name", CompareEnum.LesserOrEqual, "A" + first.Name));

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

                db.Load();

                using (var t = db.BeginTransaction())
                {
                    objs.ToList().ForEach(o => o.Id = db.Add(o));

                    t.Commit();
                }

                using (var t = db.BeginTransaction())
                {
                    var results = eval.ExecuteDelete(delete);

                    Assert.AreEqual(1, results);

                    t.Commit();

                    Assert.IsNull(db.Fetch(first.Id));
                }

                Assert.IsNull(db.Fetch(first.Id));
            }
        }
开发者ID:thehexgod,项目名称:BESSY-DB,代码行数:45,代码来源:ExpressionResolverDeleteTests.cs


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