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


C# InMemoryRepository.FindAll方法代码示例

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


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

示例1: ExecuteFindAll_With_Selector_Should_Use_Cache_After_First_Call

        public void ExecuteFindAll_With_Selector_Should_Use_Cache_After_First_Call()
        {
            var repos = new InMemoryRepository<Contact>(new StandardCachingStrategy<Contact>());

            repos.Add(new Contact { Name = "Test1" });
            repos.Add(new Contact { Name = "Test2" });

            var items = repos.FindAll(x => x.ContactId < 3, x => x.Name);
            repos.CacheUsed.ShouldBeFalse();
            items.Count().ShouldEqual(2);

            items = repos.FindAll(x => x.ContactId < 3, x => x.Name);
            repos.CacheUsed.ShouldBeTrue();
            items.Count().ShouldEqual(2);
        }
开发者ID:mgmccarthy,项目名称:SharpRepository,代码行数:15,代码来源:InMemoryCachingTests.cs

示例2: Repository_Handles_Sorting

        public void Repository_Handles_Sorting()
        {
            var repo = new InMemoryRepository<Order>();
            repo.Add(OrdersToLoad());

            // there are 2 ways to handle sorting, there is an Expression based way
            //  and a "magic string" based approach.
            // Why the 2 approaches?
            //  For convenience really.  In a Web based applicaiton sometimes it is easier to
            //  post back a string that represents the properrty that you want to sort on.

            // First, the Expression way
            var descendingOrders = repo.GetAll(new SortingOptions<Order, DateTime>(x => x.OrderDate, isDescending: true));
            descendingOrders.First().OrderId.ShouldEqual(1);

            var ascendingOrders = repo.GetAll(new SortingOptions<Order, DateTime>(x => x.OrderDate, isDescending: false));
            ascendingOrders.First().OrderId.ShouldEqual(2);

            // You can also combine sortings and selectors (See HowToUseGetSelectors for more info)
            var descendingNames = repo.GetAll(x => x.Name, new SortingOptions<Order, DateTime>(x => x.OrderDate, isDescending: true));
            descendingNames.First().ShouldEqual("Order 1");

            // The Magic String approach to sorting
            //  you can see that you don't need the second generic type (the property type to sort on), just the name of the property
            ascendingOrders = repo.GetAll(new SortingOptions<Order>("OrderDate", isDescending: false));
            ascendingOrders.First().OrderId.ShouldEqual(2);

            // using sorting with FindAll
            var minDate = DateTime.Now.AddDays(-7);
            var ordersWithinAWeek = repo.FindAll(x => x.OrderDate > minDate, new SortingOptions<Order, double>(x => x.Total, true));
            ordersWithinAWeek.Count().ShouldEqual(2);
        }
开发者ID:mgmccarthy,项目名称:SharpRepository,代码行数:32,代码来源:HowToUsePagingAndSorting.cs

示例3: FindAllShouldBeCachedWithSinglePredicateValueHash

        public void FindAllShouldBeCachedWithSinglePredicateValueHash()
        {
            var repository = new InMemoryRepository<Contact, string>(new StandardCachingStrategy<Contact, string>()); // by default uses InMemoryCache

            for (var i = 1; i < 5; i++)
            {
                repository.Add(new Contact { ContactId = i.ToString(), Name = "Contact " + i, ContactTypeId = 1 });
            }

            var contactId = "1";
            repository.FindAll(x => x.ContactId == contactId)
                .First().ContactId.ShouldEqual(contactId);

            contactId = "2";
            repository.FindAll(x => x.ContactId == contactId)
                .First().ContactId.ShouldEqual(contactId);
        }
开发者ID:nubizsoft,项目名称:SharpRepository,代码行数:17,代码来源:StandardCachingSpikes.cs

示例4: Repository_Supports_Selectors

        public void Repository_Supports_Selectors()
        {
            var repo = new InMemoryRepository<Order>();

            // let's add a couple of orders to work with
            repo.Add(new Order()
                         {
                             Name = "Order 1",
                             Total = 120.00,
                             OrderDate = new DateTime(2013, 4, 26)
                         });

            repo.Add(new Order()
                         {
                             Name = "Order 2",
                             Total = 80.00,
                             OrderDate = new DateTime(2013, 4, 24)
                         });

            // normal Get method
            var order = repo.Get(1);
            order.OrderId.ShouldEqual(1);

            // in this case we only need the order name
            var orderName = repo.Get(1, x => x.Name);
            orderName.ShouldEqual("Order 1");

            // we can also bring back an anonymous type if needed
            var anonymousType = repo.Get(1, x => new { Name = x.Name, IsExpensiveOrder = x.Total > 100.0 });
            anonymousType.IsExpensiveOrder.ShouldBeTrue();

            // or we can map it to a specific type we have defined like a ViewModel
            var viewModel = repo.Get(1, x => new OrderViewModel() {Name = x.Name, IsExpensiveOrder = x.Total > 100.0});
            viewModel.IsExpensiveOrder.ShouldBeTrue();

            // We have the same options with the GetAll, Find and FindAll as well
            orderName = repo.Find(x => x.OrderId == 2, x => x.Name);
            orderName.ShouldEqual("Order 2");

            // we can also bring back an anonymous type if needed
            var anonymousTypes = repo.GetAll(x => new { Name = x.Name, IsExpensiveOrder = x.Total > 100.0 }).ToList();
            anonymousTypes.Count.ShouldEqual(2);
            anonymousTypes.First().Name.ShouldEqual("Order 1");
            anonymousTypes.First().IsExpensiveOrder.ShouldBeTrue();

            anonymousTypes.Last().Name.ShouldEqual("Order 2");
            anonymousTypes.Last().IsExpensiveOrder.ShouldBeFalse();

            // or we can map it to a specific type we have defined like a ViewModel
            var viewModels = repo.FindAll(x => x.OrderId < 5, x => new OrderViewModel() { Name = x.Name, IsExpensiveOrder = x.Total > 100.0 }).ToList();
            viewModels.Count.ShouldEqual(2);
            viewModels.First().Name.ShouldEqual("Order 1");
            viewModels.First().IsExpensiveOrder.ShouldBeTrue();

            viewModels.Last().Name.ShouldEqual("Order 2");
            viewModels.Last().IsExpensiveOrder.ShouldBeFalse();
        }
开发者ID:mgmccarthy,项目名称:SharpRepository,代码行数:57,代码来源:HowToUseGetSelectors.cs

示例5: ExecuteFindAll_With_Paging_Should_Save_TotalItems_In_Cache

        public void ExecuteFindAll_With_Paging_Should_Save_TotalItems_In_Cache()
        {
            var repos = new InMemoryRepository<Contact>(new StandardCachingStrategy<Contact>());

            repos.Add(new Contact { ContactId = 1, Name = "Test1" });
            repos.Add(new Contact { ContactId = 2, Name = "Test2" });
            repos.Add(new Contact { ContactId = 3, Name = "Test3" });
            repos.Add(new Contact { ContactId = 4, Name = "Test4" });

            var pagingOptions = new PagingOptions<Contact>(1, 1, "Name");

            var items = repos.FindAll(x => x.ContactId >= 2, x => x.Name, pagingOptions);
            repos.CacheUsed.ShouldBeFalse();
            items.Count().ShouldEqual(1);
            pagingOptions.TotalItems.ShouldEqual(3);

            // reset paging options so the TotalItems is default
            pagingOptions = new PagingOptions<Contact>(1, 1, "Name");

            items = repos.FindAll(x => x.ContactId >= 2, x => x.Name, pagingOptions);
            repos.CacheUsed.ShouldBeTrue();
            items.Count().ShouldEqual(1);
            pagingOptions.TotalItems.ShouldEqual(3);
        }
开发者ID:mgmccarthy,项目名称:SharpRepository,代码行数:24,代码来源:InMemoryCachingTests.cs

示例6: Logging_Via_Aspects

        public void Logging_Via_Aspects()
        {
            var repository = new InMemoryRepository<Contact, int>();

            var contact1 = new Contact() {Name = "Contact 1"};
            repository.Add(contact1);
            repository.Add(new Contact() { Name = "Contact 2"});
            repository.Add(new Contact() { Name = "Contact 3"});

            contact1.Name += " EDITED";
            repository.Update(contact1);

            repository.Delete(2);

            repository.FindAll(x => x.ContactId < 50);
        }
开发者ID:mgmccarthy,项目名称:SharpRepository,代码行数:16,代码来源:LoggingSpikes.cs

示例7: CompoundKeyRepository_Should_Work

        public void CompoundKeyRepository_Should_Work()
        {
            var repository = new InMemoryRepository<CompoundKeyItemInts, int, int>();

            repository.Add(new CompoundKeyItemInts { SomeId = 1, AnotherId = 1, Title = "1-1"});
            repository.Add(new CompoundKeyItemInts { SomeId = 1, AnotherId = 2, Title = "1-2"});
            repository.Add(new CompoundKeyItemInts { SomeId = 1, AnotherId = 3, Title = "1-3"});
            repository.Add(new CompoundKeyItemInts { SomeId = 2, AnotherId = 1, Title = "2-1"});
            repository.Add(new CompoundKeyItemInts { SomeId = 2, AnotherId = 2, Title = "2-2"});
            repository.Add(new CompoundKeyItemInts { SomeId = 2, AnotherId = 3, Title = "2-3"});

            repository.Get(1, 1).Title.ShouldEqual("1-1");
            repository.Get(2, 1).Title.ShouldEqual("2-1");
            repository.Get(1, 2).Title.ShouldEqual("1-2");

            repository.FindAll(x => x.SomeId == 1).Count().ShouldEqual(3);
        }
开发者ID:mgmccarthy,项目名称:SharpRepository,代码行数:17,代码来源:CompoundKeySpikes.cs

示例8: TripleCompoundKeyRepository_Should_Work

        public void TripleCompoundKeyRepository_Should_Work()
        {
            var repository = new InMemoryRepository<TripleCompoundKeyItemInts, int, int, int>();

            repository.Add(new TripleCompoundKeyItemInts { SomeId = 1, AnotherId = 1, LastId = 10, Title = "1-1-10" });
            repository.Add(new TripleCompoundKeyItemInts { SomeId = 1, AnotherId = 2, LastId = 11, Title = "1-2-11" });
            repository.Add(new TripleCompoundKeyItemInts { SomeId = 1, AnotherId = 3, LastId = 10, Title = "1-3-10" });
            repository.Add(new TripleCompoundKeyItemInts { SomeId = 2, AnotherId = 1, LastId = 11, Title = "2-1-11" });
            repository.Add(new TripleCompoundKeyItemInts { SomeId = 2, AnotherId = 2, LastId = 10, Title = "2-2-10" });
            repository.Add(new TripleCompoundKeyItemInts { SomeId = 2, AnotherId = 3, LastId = 11, Title = "2-3-11" });

            repository.Get(1, 1, 10).Title.ShouldEqual("1-1-10");
            repository.Get(2, 1, 11).Title.ShouldEqual("2-1-11");
            repository.Get(1, 2, 11).Title.ShouldEqual("1-2-11");

            repository.FindAll(x => x.LastId == 11).Count().ShouldEqual(3);
        }
开发者ID:mgmccarthy,项目名称:SharpRepository,代码行数:17,代码来源:CompoundKeySpikes.cs


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