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


C# IRepository.FindAll方法代码示例

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


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

示例1: MatchModule

        public MatchModule(IRepository<Match> matchRepository, IRepository<Country> countryRepository)
            : base("/matches")
        {
            Get["/"] = parameters =>
                           {
                               var matches = matchRepository.FindAll();

                               var resource = matches.ToArray().Select(
                                   m => new MatchResource
                                            {
                                                Id = m.Id,
                                                Date = m.Date,
                                                Team1CountryId = m.Team1.Country.Id,
                                                Team2CountryId = m.Team2.Country.Id
                                            });

                               return Response.AsJson(resource);
                           };

            Post["/"] = parameters =>
                {
                    var resource = this.Bind<MatchResource>();

                    var country1 = countryRepository.GetById(resource.Team1CountryId);
                    if (country1 == null)
                        return HttpStatusCode.BadRequest;

                    var country2 = countryRepository.GetById(resource.Team2CountryId);
                    if (country2 == null)
                        return HttpStatusCode.BadRequest;

                    var match = Match.Create(
                        resource.Date,
                        country1,
                        country2);

                    matchRepository.Add(match);

                    return Response.AsRedirect("/matches/" + match.Id);
                };

            Get["/{id}"] = parameters =>
                {
                    var match = matchRepository.GetById((int)parameters.Id);
                    if (match == null)
                        return HttpStatusCode.NotFound;

                    return Response.AsJson(new
                        {
                            Date = match.Date,
                            Team1 = match.Team1,
                            Team2 = match.Team2
                        });
                };
        }
开发者ID:christensena,项目名称:DDDIntro,代码行数:55,代码来源:MatchModule.cs

示例2: FindAll_Should_Return_All_Items_Which_Satisfy_Composite_Specification

        public void FindAll_Should_Return_All_Items_Which_Satisfy_Composite_Specification(IRepository<Contact, string> repository)
        {
            for (int i = 1; i <= 3; i++)
            {
                var contact = new Contact { Name = "Test User " + i };
                repository.Add(contact);
            }

            var result = repository.FindAll(new Specification<Contact>(p => p.Name == "Test User 1").OrElse(new Specification<Contact>(p => p.Name == "Test User 2")));
            result.Count().ShouldEqual(2);
        }
开发者ID:mgmccarthy,项目名称:SharpRepository,代码行数:11,代码来源:RepositoryFindAllTests.cs

示例3: FindAll_Should_Return_All_Items_Which_Satisfy_Composite_Specification_With_Paging_And_Sort_Descending

        public void FindAll_Should_Return_All_Items_Which_Satisfy_Composite_Specification_With_Paging_And_Sort_Descending(IRepository<Contact, string> repository)
        {
            const int resultingPage = 2;
            const int pageSize = 2;
            var queryOptions = new PagingOptions<Contact>(resultingPage, pageSize, "Name", true);

            for (int i = 1; i <= 10; i++)
            {
                var contact = new Contact { Name = "Test User " + i };
                repository.Add(contact);
            }

            IEnumerable<Contact> result = repository
                .FindAll(new Specification<Contact>(p => p.Name == "Test User 1")
                                .OrElse(new Specification<Contact>(p => p.Name == "Test User 5")
                                        .OrElse(new Specification<Contact>(p => p.Name == "Test User 8"))),
                            queryOptions);

            result.Count().ShouldEqual(1);
            queryOptions.TotalItems.ShouldEqual(3);
            result.First().Name.ShouldEqual("Test User 1");
        }
开发者ID:mgmccarthy,项目名称:SharpRepository,代码行数:22,代码来源:RepositoryFindAllTests.cs

示例4: GetFirstEmployee_noParams_employee

        public void GetFirstEmployee_noParams_employee()
        {
            Employee employee;

            using (var dbContext = new DatabaseContext(testUser, testPass))
            {
                employeeRepository = new EmployeesRepository(dbContext);
                employee = employeeRepository.FindAll().FirstOrDefault();
            }

            Assert.IsNotNull(employee);
        }
开发者ID:agrigul,项目名称:CisBonusesManager,代码行数:12,代码来源:EmployeeRepositoryTests.cs

示例5: FindAll_Should_Return_All_Items_Which_Satisfy_Specification_With_Paging_MagicString

        public void FindAll_Should_Return_All_Items_Which_Satisfy_Specification_With_Paging_MagicString(IRepository<Contact, string> repository)
        {
            const int resultingPage = 2;
            const int pageSize = 2;
            const int totalItems = 10;

            var queryOptions = new PagingOptions<Contact>(resultingPage, pageSize, "Name");

            for (int i = 1; i <= totalItems; i++)
            {
                var contact = new Contact { Name = "Test User " + i, ContactTypeId = i };
                repository.Add(contact);
            }

            // this fails for RavenDb because the ContactId is an int but is being used as the key, so the check on ContactId <= 5 is doing a string comparison and including ContactId = 10 as well
            //  need to look into why this happens and how to get around it
            var result = repository.FindAll(new Specification<Contact>(p => p.ContactTypeId <= totalItems / 2), queryOptions);
            result.Count().ShouldEqual(pageSize);
            queryOptions.TotalItems.ShouldEqual(totalItems / 2);
            result.First().Name.ShouldEqual("Test User 3");
        }
开发者ID:mgmccarthy,项目名称:SharpRepository,代码行数:21,代码来源:RepositoryFindAllTests.cs

示例6: FindAll_Should_Return_All_Items_Which_Satisfy_Specification

        public void FindAll_Should_Return_All_Items_Which_Satisfy_Specification(IRepository<Contact, string> repository)
        {
            for (int i = 1; i <= 3; i++)
            {
                var contact = new Contact {Name = "Test User " + i};
                repository.Add(contact);
            }

            var result = repository.FindAll(new Specification<Contact>(p => p.Name == "Test User 1")); // Note: Raven doesn't like p.Name.Equals("...");
            result.Count().ShouldEqual(1);
        }
开发者ID:mgmccarthy,项目名称:SharpRepository,代码行数:11,代码来源:RepositoryFindAllTests.cs

示例7: StackLoader

 public StackLoader(IRepository<Stack> stackRepository, IRepository<Instance> instanceRepository)
 {
     _stackRepository = stackRepository;
     _instanceRepository = instanceRepository;
     _repositoryInstances = new Lazy<List<Instance>>(() => _instanceRepository.FindAll().ToList());
 }
开发者ID:nelsonwellswku,项目名称:stack-it-net,代码行数:6,代码来源:StackLoader.cs

示例8: GetPagedJsonBonuses

        public JsonResult GetPagedJsonBonuses(int take, int skip)
        {
            PagedResponse<BonusAggregate> bonuses;

            var filteredRequest = new FilteredRequest(Request.Params);

            using (var dbContext = new DatabaseContext())
            {
                BonusesRepository = new BonusesRepository(dbContext);
                bonuses = BonusesRepository.FindAll(skip,
                                                    take,
                                                    filteredRequest.SortingField,
                                                    filteredRequest.Direction,
                                                    filteredRequest.FilterField,
                                                    filteredRequest.FilterPattern);
            }

            return Json(bonuses, JsonRequestBehavior.AllowGet);
        }
开发者ID:agrigul,项目名称:CisBonusesManager,代码行数:19,代码来源:BonusesController.cs

示例9: Save_BonusesList_2BonusesUpdated

        public void Save_BonusesList_2BonusesUpdated()
        {
            IList<BonusAggregate> bonusesToUpdate;
            IList<BonusAggregate> updatedBonuses = new List<BonusAggregate>();
            var bonusesIds = new int[2];

            string newComment = "comment on " + DateTime.Now;
            using (var dbContext = new DatabaseContext(TestUser, TestPass))
            {
                bonusRepository = new BonusesRepository(dbContext);
                bonusesToUpdate = bonusRepository.FindAll().Take(2).ToList();
                bonusesToUpdate[0].Comment = newComment;
                bonusesToUpdate[1].Comment = newComment;

                bonusesIds[0] = bonusesToUpdate[0].BonusId;
                bonusesIds[1] = bonusesToUpdate[1].BonusId;
                bonusRepository.Save(bonusesToUpdate);
            }

            using (var dbContext = new DatabaseContext(TestUser, TestPass))
            {
                bonusRepository = new BonusesRepository(dbContext);
                updatedBonuses.Add(bonusRepository.GetById(bonusesIds[0]));
                updatedBonuses.Add(bonusRepository.GetById(bonusesIds[1]));
            }

            Assert.AreEqual(updatedBonuses[0].Comment, newComment);
            Assert.AreEqual(updatedBonuses[1].Comment, newComment);
        }
开发者ID:agrigul,项目名称:CisBonusesManager,代码行数:29,代码来源:BonusRepositoryTests.cs

示例10: Save_BonusesList_2BonusesAdded

        public void Save_BonusesList_2BonusesAdded()
        {
            int numberOfItemsBeforSave;

            int numberOfCurrentBonuses;
            using (var dbContext = new DatabaseContext(TestUser, TestPass))
            {
                bonusFactory = new BonusFactory(new EmployeesRepository(dbContext));
                var bonusesList = new List<BonusAggregate>
                                        {
                                          bonusFactory.Create(GetEmployeeById(4), DateTime.Now, 100),
                                          bonusFactory.Create(GetEmployeeById(5), DateTime.Now, 90)
                                        };

                bonusRepository = new BonusesRepository(dbContext);
                numberOfItemsBeforSave = bonusRepository.FindAll().Count();
                bonusRepository.Save(bonusesList);
                numberOfCurrentBonuses = bonusRepository.FindAll().Count();
            }

            Assert.AreEqual(numberOfCurrentBonuses - 2, numberOfItemsBeforSave);
        }
开发者ID:agrigul,项目名称:CisBonusesManager,代码行数:22,代码来源:BonusRepositoryTests.cs

示例11: FindAll_noParams_SomeBonuses

        public void FindAll_noParams_SomeBonuses()
        {
            IList<BonusAggregate> bonuses;

            using (var dbContext = new DatabaseContext(TestUser, TestPass))
            {
                bonusRepository = new BonusesRepository(dbContext);
                bonuses = bonusRepository.FindAll();
            }

            Assert.IsNotNull(bonuses);
            Assert.AreNotEqual(0, bonuses.Count);
        }
开发者ID:agrigul,项目名称:CisBonusesManager,代码行数:13,代码来源:BonusRepositoryTests.cs

示例12: FindAll_NoParams_EmployeeExists

        public void FindAll_NoParams_EmployeeExists()
        {
            BonusAggregate bonusAggregate;

            using (var dbContext = new DatabaseContext(TestUser, TestPass))
            {
                bonusRepository = new BonusesRepository(dbContext);
                bonusAggregate = bonusRepository.FindAll().First();
            }

            Assert.IsNotNull(bonusAggregate.Employee);
        }
开发者ID:agrigul,项目名称:CisBonusesManager,代码行数:12,代码来源:BonusRepositoryTests.cs

示例13: FindAllWithPaging_Skip2Take3_CorrectTotalCount

        public void FindAllWithPaging_Skip2Take3_CorrectTotalCount()
        {
            IList<BonusAggregate> notSkipedBonuses;
            PagedResponse<BonusAggregate> skipedBonuses;

            using (var dbContext = new DatabaseContext(TestUser, TestPass))
            {
                bonusRepository = new BonusesRepository(dbContext);
                notSkipedBonuses = bonusRepository.FindAll();
                skipedBonuses = bonusRepository.FindAllWithPaging(2, 3);
            }
            Assert.AreEqual(skipedBonuses.TotalCount, notSkipedBonuses.Count);
        }
开发者ID:agrigul,项目名称:CisBonusesManager,代码行数:13,代码来源:BonusRepositoryTests.cs

示例14: CountryModule

        // TODO: let's do content negotiation ourselves unless there is a nice
        // way to do it in Nancy like there seems to be for most things
        public CountryModule(IRepository<Domain.Country> countryRepository, CountryFactory countryFactory)
            : base("/countries")
        {
            Get["/"] = parameters =>
                {
                    var countryResources = countryRepository.FindAll()
                        .Select(c => new Country {id = c.Id.ToString(), Name = c.Name});

                    var resource = countryResources.ToArray();

                    return Response.AsJson(resource);
                };

            Get["/{id}"] = parameters =>
                {
                    var country = countryRepository.GetById((int)parameters.id);
                    if (country == null)
                        return HttpStatusCode.NotFound;

                    var resource = new Country {id = country.Id.ToString(), Name = country.Name};

                    return Response.AsJson(resource);
                };

            Post["/"] = parameters =>
                {
                    var countryResource = this.Bind<Country>(blacklistedProperties:"id");

                    var validationResult = this.Validate(countryResource);
                    if (! validationResult.IsValid)
                    {
                        var response = Response.AsJson(validationResult.Errors);
                        response.StatusCode = HttpStatusCode.BadRequest;
                        return response;
                    }

                    var country = countryFactory.CreateCountry(countryResource.Name);
                    countryRepository.Add(country);

                    return Response.AsRedirect("/countries/"+country.Id);
                };

            Put["/{id}"] = parameters =>
                {
                    var country = countryRepository.GetById((int) parameters.id);
                    if (country == null)
                        return HttpStatusCode.NotFound; // this correct for a put? should probably be some error

                    // we don't actually support updates to countries!
                    //country.Name = parameters.Name;

                    return Response.AsRedirect("/countries/" + country.Id);
                };

            Delete["/{id}"] = parameters =>
                {
                    var country = countryRepository.GetById((int)parameters.id);
                    if (country == null)
                        return HttpStatusCode.NotFound; // this correct for a put? should probably be some error

                    countryRepository.Remove(country);

                    return HttpStatusCode.OK;
                };
        }
开发者ID:christensena,项目名称:DDDIntro,代码行数:67,代码来源:CountryModule.cs


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