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


C# System.Collections.Generic.AsQueryable方法代码示例

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


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

示例1: SearchUsesServiceMethodIfServerSupportsIt

        public void SearchUsesServiceMethodIfServerSupportsIt()
        {
            // Arrange
            var client = new Mock<IHttpClient>();
            var context = new Mock<IDataServiceContext>();
            var repository = new Mock<DataServicePackageRepository>(client.Object) { CallBase = true };
            var packages = new[] { 
                PackageUtility.CreatePackage("A", description:"New and aweseome"),
                PackageUtility.CreatePackage("B", description:"old and bad"),
                PackageUtility.CreatePackage("C", description:"rich")
            };
            repository.Setup(m => m.GetPackages()).Returns(packages.AsQueryable());
            repository.Object.Context = context.Object;
            context.Setup(m => m.SupportsServiceMethod("Search")).Returns(true);
            context.Setup(m => m.CreateQuery<DataServicePackage>(It.IsAny<string>(), It.IsAny<IDictionary<string, object>>()))
                   .Callback<string, IDictionary<string, object>>((entitySet, parameters) =>
                   {
                       // Assert
                       Assert.Equal("Search", entitySet);
                       Assert.Equal(2, parameters.Count);
                       Assert.Equal("'old'", parameters["searchTerm"]);
                       Assert.Equal("''", parameters["targetFramework"]);
                   })
                   .Returns(new Mock<IDataServiceQuery<DataServicePackage>>().Object);

            // Act
            repository.Object.Search("old", allowPrereleaseVersions: false);
        }
开发者ID:xero-github,项目名称:Nuget,代码行数:28,代码来源:DataServicePackageRepositoryTest.cs

示例2: SortByPorpertyPath

        public void SortByPorpertyPath()
        {
            var source = new[]
                             {
                                 new TestSource{ Inner = new InnerType{Complex = new TestSource {String = "foo", Int = 1}}}, 
                                 new TestSource{ Inner = new InnerType{Complex = new TestSource {String = "bar", Int = 99}}},
                                 new TestSource{ Inner = new InnerType{Complex = new TestSource {String = "baz", Int = 3}}}, 
                                 new TestSource{ Inner = new InnerType{Complex = new TestSource {String = "foo", Int = 8}}},
                                 new TestSource{ Inner = new InnerType{Complex = new TestSource {String = "foo", Int = 5}}}, 
                                 new TestSource{ Inner = new InnerType{Complex = new TestSource {String = "zap", Int = 16}}},
                                 new TestSource{ Inner = new InnerType{Complex = new TestSource {String = "foo", Int = 7}}}
                             };

            var sortSettings = new List<SortSetting>
                                   {
                                       new SortSetting {PropertyPath = "Inner.Complex.String", SortOrder = SortOrder.Ascending},
                                       new SortSetting {PropertyPath = "Inner.Complex.Int", SortOrder = SortOrder.Descending}
                                   };

            IQueryable<TestSource> queryable = source.AsQueryable();

            IOrderedQueryable<TestSource> expectedSortedQueryable = queryable.OrderBy(s => s.Inner.Complex.String).ThenByDescending(s => s.Inner.Complex.Int);

            var result = _builder.Sort(queryable, sortSettings);

            TestUtil.AssertModels(expectedSortedQueryable.ToList(), result.ToList());
        }
开发者ID:OldWiseLlama,项目名称:DynamicExpressionBuilder,代码行数:27,代码来源:SortExpressionBuilderTests.cs

示例3: CreateUsingFeatureClass

        public void CreateUsingFeatureClass()
        {
            var city1 = new City { Geometry = new Point(0, 0, 0), Name = "Amsterdam", Population = 1500000 };
            var city2 = new City { Geometry = new Point(1, 1, 1), Name = "The Hague", Population = 9000000 };

            var cities = new [] { city1, city2 };

            var dataSource = new MemoryFeatureDataSource { Features = cities.AsQueryable() };

            dataSource.FeatureAttributes.Count
                     .Should("query attributes, automatically reconstructed from added features").Be.EqualTo(2);
        }
开发者ID:suryapratap,项目名称:SharpMap3-Thoughts,代码行数:12,代码来源:MemoryFeatureDataSourceTest.cs

示例4: Get

        public IQueryable<SampleDataItem> Get()
        {
            var dataItems = new[]
                {
                        new SampleDataItem { SomeProperty = 1 },
                        new SampleDataItem { SomeProperty = 2 },
                        new SampleDataItem { SomeProperty = 3 },
                        new SampleDataItem { SomeProperty = 4 },
                };

            return dataItems.AsQueryable();
        }
开发者ID:fgq841103,项目名称:spring-net,代码行数:12,代码来源:OdataController.cs

示例5: CreateContentRepository

		public static IRepository<Content> CreateContentRepository()
		{
			var repository = MockRepository.GenerateStub<IRepository<Content>>();

			var content = new[]
			{
				new Content { Name = "Page 1"},
				new Content { Name = "Page 2"}
			};

			repository.Expect(x => x.GetAll()).Return(content.AsQueryable());
			return repository;
		}
开发者ID:somlea-george,项目名称:sutekishop,代码行数:13,代码来源:MockRepositoryBuilder.cs

示例6: CreateSlots

        private IQueryable<ISlot> CreateSlots([NotNull] CallInfo arg)
        {
            var one = Substitute.For <ISlot>();
            one.DayId.Returns(1);

            var two = Substitute.For <ISlot>();
            two.DayId.Returns(2);

            var list = new[]
                       {
                           one,
                           two
                       };

            return list.AsQueryable();
        }
开发者ID:tschroedter,项目名称:DoctorsAppointment,代码行数:16,代码来源:SlotsRepositoryTests.cs

示例7: NullComparer

        public void NullComparer()
        {
            CustomerRec[] outer = new []
            {
                new CustomerRec{ name = "Prakash", custID = 98022 },
                new CustomerRec{ name = "Tim", custID = 99021 },
                new CustomerRec{ name = "Robert", custID = 99022 }
            };
            AnagramRec[] inner = new []
            {
                new AnagramRec{ name = "miT", orderID = 43455, total = 10 },
                new AnagramRec{ name = "Prakash", orderID = 323232, total = 9 }
            };
            JoinRec[] expected = new [] { new JoinRec{ name = "Prakash", orderID = 323232, total = 9 } };

            Assert.Equal(expected, outer.AsQueryable().Join(inner.AsQueryable(), e => e.name, e => e.name, (cr, or) => new JoinRec { name = cr.name, orderID = or.orderID, total = or.total }, null));
        }
开发者ID:dotnet,项目名称:corefx,代码行数:17,代码来源:JoinTests.cs

示例8: KeySelectorCalled

        public void KeySelectorCalled()
        {
            var source = new[]
            {
                new { Name = "Tim", Score = 90 },
                new { Name = "Robert", Score = 45 },
                new { Name = "Prakash", Score = 99 }
            };
            var expected = new[]
            {
                new { Name = "Prakash", Score = 99 },
                new { Name = "Robert", Score = 45 },
                new { Name = "Tim", Score = 90 }
            };

            Assert.Equal(expected, source.AsQueryable().OrderBy(e => e.Name, null));
        }
开发者ID:dotnet,项目名称:corefx,代码行数:17,代码来源:OrderByTests.cs

示例9: Should_use_nested_expression

            public void Should_use_nested_expression()
            {
                var items = new[]
                {
                    new Parent
                    {
                        Children = new List<Child>()
                        {
                            new Child() { Value = 4 },
                            new Child() { Value = 5 },
                        }
                    }
                };

                var projected = items.AsQueryable().Project().To<ParentDto>().ToList();

                projected[0].TotalSum.ShouldEqual(9);
            }
开发者ID:gonzalogilrepositorio,项目名称:Proyecto-ComIT,代码行数:18,代码来源:NestedExpressionsMapFromTests.cs

示例10: TestStartsWithOperatorString

        public void TestStartsWithOperatorString()
        {
            const string f = "f";
            var source = new[]
                             {
                                 new TestSource {String = "foo", Int = 1}, new TestSource {String = "bar", Int = 2},
                                 new TestSource {String = "baz", Int = 3}, new TestSource {String = "fii", Int = 4},
                                 new TestSource {String = "fuu", Int = 5}, new TestSource {String = "zap", Int = 6},
                                 new TestSource {String = "faa", Int = 7}
                             };

            var expectedResultList = source.Where(t => t.String.StartsWith(f)).ToList();

            var filter = new FilterSetting { OperatorName = FilterOperators.StartsWithOperator, PropertyPath = "String", Value = f };

            var result = _builder.Filter(source.AsQueryable(), new[] { filter });

            TestUtil.AssertModels(expectedResultList, result.ToList());
        }
开发者ID:OldWiseLlama,项目名称:DynamicExpressionBuilder,代码行数:19,代码来源:FilterExpressionBuilderTests.cs

示例11: ExpressionTests_Sum2

        public void ExpressionTests_Sum2()
        {
            //Arrange
            var initValues = new[]
            {
                new SimpleValuesModel { FloatValue = 1 },
                new SimpleValuesModel { FloatValue = 2 },
                new SimpleValuesModel { FloatValue = 3 },
            };

            var qry = initValues.AsQueryable();

            //Act
            var result = qry.Select("FloatValue").Sum();
            var result2 = ((IQueryable<float>)qry.Select("FloatValue")).Sum();

            //Assert
            Assert.AreEqual(6.0f, result);
            Assert.AreEqual(6.0f, result2);
        }
开发者ID:StefH,项目名称:System.Linq.Dynamic,代码行数:20,代码来源:ExpressionTests.cs

示例12: AscendingKeyThenDescendingKey

        public void AscendingKeyThenDescendingKey()
        {
            var source = new[]
            {
                new { Name = "Jim", City = "Minneapolis", Country = "USA" },
                new { Name = "Tim", City = "Seattle", Country = "USA" },
                new { Name = "Philip", City = "Orlando", Country = "USA" },
                new { Name = "Chris", City = "London", Country = "UK" },
                new { Name = "Rob", City = "Kent", Country = "UK" }
            };
            var expected = new[]
            {
                new { Name = "Chris", City = "London", Country = "UK" },
                new { Name = "Rob", City = "Kent", Country = "UK" },
                new { Name = "Tim", City = "Seattle", Country = "USA" },
                new { Name = "Philip", City = "Orlando", Country = "USA" },
                new { Name = "Jim", City = "Minneapolis", Country = "USA" }
            };

            Assert.Equal(expected, source.AsQueryable().OrderBy(e => e.Country).ThenByDescending(e => e.City));
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:21,代码来源:ThenByDescendingTests.cs

示例13: FirstOuterMatchesLastInnerLastOuterMatchesFirstInnerSameNumberElements

        public void FirstOuterMatchesLastInnerLastOuterMatchesFirstInnerSameNumberElements()
        {
            CustomerRec[] outer = new []
            {
                new CustomerRec{ name = "Prakash", custID = 98022 },
                new CustomerRec{ name = "Tim", custID = 99021 },
                new CustomerRec{ name = "Robert", custID = 99022 }
            };
            OrderRec[] inner = new []
            {
                new OrderRec{ orderID = 45321, custID = 99022, total = 50 },
                new OrderRec{ orderID = 43421, custID = 29022, total = 20 },
                new OrderRec{ orderID = 95421, custID = 98022, total = 9 }
            };
            JoinRec[] expected = new []
            {
                new JoinRec{ name = "Prakash", orderID = 95421, total = 9 },
                new JoinRec{ name = "Robert", orderID = 45321, total = 50 }
            };

            Assert.Equal(expected, outer.AsQueryable().Join(inner.AsQueryable(), e => e.custID, e => e.custID, (cr, or) => new JoinRec { name = cr.name, orderID = or.orderID, total = or.total }));
        }
开发者ID:dotnet,项目名称:corefx,代码行数:22,代码来源:JoinTests.cs

示例14: SearchUsesDefaultSearchLogicIfServerDoesnotSupportServiceMethod

        public void SearchUsesDefaultSearchLogicIfServerDoesnotSupportServiceMethod()
        {
            // Arrange
            var client = new Mock<IHttpClient>();
            var context = new Mock<IDataServiceContext>();
            var repository = new Mock<DataServicePackageRepository>(client.Object) { CallBase = true };
            var packages = new[] { 
                PackageUtility.CreatePackage("A", description:"New and aweseome"),
                PackageUtility.CreatePackage("B", description:"old and bad"),
                PackageUtility.CreatePackage("C", description:"rich")
            };
            repository.Setup(m => m.GetPackages()).Returns(packages.AsQueryable());
            repository.Object.Context = context.Object;
            context.Setup(m => m.SupportsServiceMethod("Search")).Returns(false);

            // Act
            var results = repository.Object.Search("old", allowPrereleaseVersions: false).ToList();

            // Assert
            Assert.Equal(1, results.Count);
            Assert.Equal("B", results[0].Id);
        }
开发者ID:xero-github,项目名称:Nuget,代码行数:22,代码来源:DataServicePackageRepositoryTest.cs

示例15: SortByImmediateProperties

        public void SortByImmediateProperties()
        {
            var source = new[]
                             {
                                 new TestSource {String = "foo", Int = 1}, new TestSource {String = "bar", Int = 2},
                                 new TestSource {String = "baz", Int = 2}, new TestSource {String = "foo", Int = 8},
                                 new TestSource {String = "foo", Int = 99}, new TestSource {String = "zap", Int = 6},
                                 new TestSource {String = "foo", Int = 7}
                             };

            var sortSettings = new List<SortSetting>
                                   {
                                       new SortSetting {PropertyPath = "String", SortOrder = SortOrder.Ascending},
                                       new SortSetting {PropertyPath = "Int", SortOrder = SortOrder.Descending}
                                   };

            IQueryable<TestSource> queryable = source.AsQueryable();

            IOrderedQueryable<TestSource> expectedSortedQueryable = queryable.OrderBy(s => s.String).ThenByDescending(s => s.Int);

            var result = _builder.Sort(queryable, sortSettings);

            TestUtil.AssertModels(expectedSortedQueryable.ToList(), result.ToList());
        }
开发者ID:OldWiseLlama,项目名称:DynamicExpressionBuilder,代码行数:24,代码来源:SortExpressionBuilderTests.cs


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