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


C# MongoRepository.Count方法代码示例

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


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

示例1: FirstTest

        public void FirstTest()
        {
            var repository = new MongoRepository<ClassTest>(Configuration.TestCollection);

            var count = repository.Count();

            Assert.AreEqual(0, count);
        }
开发者ID:nchistyakov,项目名称:MongoRepository,代码行数:8,代码来源:ComplexRepositoryTests.cs

示例2: TestCountOne

        public void TestCountOne()
        {
            var repository = new MongoRepository<ClassTest>(Configuration.TestCollection);
            repository.Add(new ClassTest());

            var count = repository.Count();

            Assert.AreEqual(1, count);
        }
开发者ID:nchistyakov,项目名称:MongoRepository,代码行数:9,代码来源:RepositoryTests.cs

示例3: TestCountOne

        public void TestCountOne()
        {
            var repository = new MongoRepository<ClassTest>(Configuration.TestCollection);

            var classTest = new ClassTest()
                {
                    IntProperty = 10,
                    ChildClassTests = new List<ChildClassTest>()
                        {
                            new ChildClassTest() {StringProperty = "first string"},
                            new ChildClassTest() {StringProperty = "second string"}
                        }
                };

            repository.Add(classTest);

            var count = repository.Count();

            Assert.AreEqual(1, count);
        }
开发者ID:nchistyakov,项目名称:MongoRepository,代码行数:20,代码来源:ComplexRepositoryTests.cs

示例4: BatchTest

        public void BatchTest()
        {
            IRepository<Customer> _customerRepo = new MongoRepository<Customer>();

            var custlist = new List<Customer>(new Customer[] {
                new Customer() { FirstName = "Customer A" },
                new Customer() { FirstName = "Client B" },
                new Customer() { FirstName = "Customer C" },
                new Customer() { FirstName = "Client D" },
                new Customer() { FirstName = "Customer E" },
                new Customer() { FirstName = "Client F" },
                new Customer() { FirstName = "Customer G" },
            });

            //Insert batch
            _customerRepo.Add(custlist);

            var count = _customerRepo.Count();
            Assert.AreEqual(7, count);
            foreach (Customer c in custlist)
                Assert.AreNotEqual(new string('0', 24), c.Id);

            //Update batch
            foreach (Customer c in custlist)
                c.LastName = c.FirstName;
            _customerRepo.Update(custlist);

            foreach (Customer c in _customerRepo)
                Assert.AreEqual(c.FirstName, c.LastName);

            //Delete by criteria
            _customerRepo.Delete(f => f.FirstName.StartsWith("Client"));

            count = _customerRepo.Count();
            Assert.AreEqual(4, count);

            //Delete specific object
            _customerRepo.Delete(custlist[0]);

            //Test AsQueryable
            var selectedcustomers = from cust in _customerRepo
                                    where cust.LastName.EndsWith("C") || cust.LastName.EndsWith("G")
                                    select cust;

            Assert.AreEqual(2, selectedcustomers.ToList().Count);

            count = _customerRepo.Count();
            Assert.AreEqual(3, count);

            //Drop entire repo
            new MongoRepositoryManager<Customer>().Drop();

            count = _customerRepo.Count();
            Assert.AreEqual(0, count);
        }
开发者ID:rodolfofadino,项目名称:MongoRepository-Fork,代码行数:55,代码来源:RepoTests.cs

示例5: CustomIDTypeTest

        public void CustomIDTypeTest()
        {
            var xint = new MongoRepository<IntCustomer, int>();
            xint.Add(new IntCustomer() { Id = 1, Name = "Test A" });
            xint.Add(new IntCustomer() { Id = 2, Name = "Test B" });

            var yint = xint.GetById(2);
            Assert.AreEqual(yint.Name, "Test B");

            xint.Delete(2);
            Assert.AreEqual(1, xint.Count());
        }
开发者ID:rodolfofadino,项目名称:MongoRepository-Fork,代码行数:12,代码来源:RepoTests.cs

示例6: CustomIDTest

        public void CustomIDTest()
        {
            var x = new MongoRepository<CustomIDEntity>();
            var xm = new MongoRepositoryManager<CustomIDEntity>();

            x.Add(new CustomIDEntity() { Id = "aaa" });

            Assert.IsTrue(xm.Exists);
            Assert.IsInstanceOfType(x.GetById("aaa"), typeof(CustomIDEntity));

            Assert.AreEqual("aaa", x.GetById("aaa").Id);

            x.Delete("aaa");
            Assert.AreEqual(0, x.Count());

            var y = new MongoRepository<CustomIDEntityCustomCollection>();
            var ym = new MongoRepositoryManager<CustomIDEntityCustomCollection>();

            y.Add(new CustomIDEntityCustomCollection() { Id = "xyz" });

            Assert.IsTrue(ym.Exists);
            Assert.AreEqual(ym.Name, "MyTestCollection");
            Assert.AreEqual(y.CollectionName, "MyTestCollection");
            Assert.IsInstanceOfType(y.GetById("xyz"), typeof(CustomIDEntityCustomCollection));

            y.Delete("xyz");
            Assert.AreEqual(0, y.Count());
        }
开发者ID:rodolfofadino,项目名称:MongoRepository-Fork,代码行数:28,代码来源:RepoTests.cs

示例7: Discussion572382

        public void Discussion572382()
        {
            var repo = new MongoRepository<ClassA>() { 
                new ClassB() { Prop1 = "A", Prop2 = "B" } ,
                new ClassC() { Prop1 = "A", Prop3 = "C" }
            };

            Assert.AreEqual(2, repo.Count());

            Assert.AreEqual(2, repo.OfType<ClassA>().Count());
            Assert.AreEqual(1, repo.OfType<ClassB>().Count());
            Assert.AreEqual(1, repo.OfType<ClassC>().Count());
        }
开发者ID:Mantisimo,项目名称:MongoRepository,代码行数:13,代码来源:RepoTests.cs


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