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


C# System.AsQueryable方法代码示例

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


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

示例1: TestPocoTypeMapping

        public void TestPocoTypeMapping()
        {
            var products = new[]
            {
                new Product {Id = Guid.NewGuid(), Title = "ProductA", CreatedUser = new User {Name = "UserA"}, OrderLines = new List<OrderLine>()},
                new Product {Id = Guid.NewGuid(), Title = "ProductB", CreatedUser = null, OrderLines = new List<OrderLine>()},
            };

            var resultQuery = products.AsQueryable().ProjectToType<ProductDTO>();
            var expectedQuery = from Param_0 in products.AsQueryable()
                                select new ProductDTO
                                {
                                    Id = Param_0.Id,
                                    Title = Param_0.Title,
                                    CreatedUserName = Param_0.CreatedUser.Name,
                                    ModifiedUser = Param_0.ModifiedUser == null ? null : new UserDTO { Id = Param_0.ModifiedUser.Id, Email = Param_0.ModifiedUser.Email },
                                    OrderLines = (from Param_1 in Param_0.OrderLines
                                                  select new OrderLineListDTO
                                                  {
                                                      Id = Param_1.Id,
                                                      UnitPrice = Param_1.UnitPrice,
                                                      Amount = Param_1.Amount,
                                                      Discount = Param_1.Discount,
                                                  }).ToList()
                                };
            resultQuery.ToString().ShouldBe(expectedQuery.ToString());
        }
开发者ID:centur,项目名称:Mapster,代码行数:27,代码来源:WhenProjecting.cs

示例2: TestFilter

        public void TestFilter()
        {
            var filter = new Filter
            {
                Name = "pwic",
                FilterCriterias ={
                    new FilterCriteria{
                        PropertyName="Property",
                        PropertyValue="pwic"
                    }
                }
            };
            var source = new[] {
                new {
                    Property = "pwic",
                    Children = new[] { new { Property1 = "pwic1",Property2 = "1pwic" }, new { Property1 = "pwic2",Property2 = "2pwic" }, new { Property1 = "pwic3",Property2 = "2pwic" } }
                },
                new {
                    Property = "pwet",
                    Children = new[]{new { Property1 = "pwet1",Property2 = "1pwet"  } }
                }
            };
            var fqb = FilterQueryBuilder.Create(source.AsQueryable());
            fqb.Visit(filter);

            Assert.AreEqual("pwic", fqb.Query.Single().Property);

            filter = new Filter
            {
                Name = "pwic",
                FilterCriterias ={
                    new FilterCriteria{
                        PropertyName="Children.Property1",
                        PropertyValue="pwic",
                        FilterOperator=FilterOperator.StartsWith,
                        FilterCriterias={
                            new FilterCriteria{
                                PropertyName=".Property2",
                                PropertyValue="2pwic",
                                FilterOperator=FilterOperator.Equal,
                            }
                        }
                    }
                }
            };

            fqb = FilterQueryBuilder.Create(source.AsQueryable());
            fqb.Visit(filter);

            Assert.AreEqual(source.Count(it => it.Children.Any(c => c.Property1.StartsWith("pwic") && c.Property2 == "2pwic")), fqb.Query.Count());
        }
开发者ID:npenin,项目名称:thewheel-dotnet,代码行数:51,代码来源:UnitTest1.cs

示例3: InlineMethodWithTwoArgs

        public void InlineMethodWithTwoArgs()
        {
            var employees = new[] { new Employee { FirstName = "Test", LastName = "User" } };

            var expected = (from employee in employees.AsQueryable()
                            where ("Mr " + employee.FirstName + " " + employee.LastName + " Jr.") == "Mr Test User Jr."
                            select employee);

            var actual = (from employee in employees.AsQueryable()
                          where employee.FullNameMethod("Mr ", " Jr.") == "Mr Test User Jr."
                          select employee).Decompile();

            Assert.Equal(expected.Expression.ToString(), actual.Expression.ToString());
        }
开发者ID:juankakode,项目名称:DelegateDecompiler,代码行数:14,代码来源:QueryableExtensionsTests.cs

示例4: InlineProperty

        public void InlineProperty()
        {
            var employees = new[] { new Employee { FirstName = "Test", LastName = "User" } };

            var expected = (from employee in employees.AsQueryable()
                            where (employee.FirstName + " " + employee.LastName) == "Test User"
                            select employee);

            var actual = (from employee in employees.AsQueryable()
                          where employee.FullName == "Test User"
                          select employee).Decompile();

            Assert.Equal(expected.Expression.ToString(), actual.Expression.ToString());
        }
开发者ID:juankakode,项目名称:DelegateDecompiler,代码行数:14,代码来源:QueryableExtensionsTests.cs

示例5: ConcatNonStringInlineProperty

        public void ConcatNonStringInlineProperty()
        {
            var employees = new[] { new Employee { FirstName = "Test", LastName = "User", From = 0, To = 100 } };

            var expected = (from employee in employees.AsQueryable()
                            where (employee.From + "-" + employee.To) == "0-100"
                            select employee);

            var actual = (from employee in employees.AsQueryable()
                          where employee.FromTo == "0-100"
                          select employee).Decompile();

            Assert.AreEqual(expected.Expression.ToString(), actual.Expression.ToString());
        }
开发者ID:hazzik,项目名称:DelegateDecompiler,代码行数:14,代码来源:QueryableExtensionsTests.cs

示例6: InlineBooleanProperty

        public void InlineBooleanProperty()
        {
            var employees = new[] { new Employee { FirstName = "Test", LastName = "User" } };

            var expected = (from employee in employees.AsQueryable()
                            where true
                            select employee);

            var actual = (from employee in employees.AsQueryable()
                          where employee.IsActive
                          select employee).Decompile();

            Assert.Equal(expected.Expression.ToString(), actual.Expression.ToString());
        }
开发者ID:juankakode,项目名称:DelegateDecompiler,代码行数:14,代码来源:QueryableExtensionsTests.cs

示例7: ByValue_Queryable_CanDisallowNull

 public void ByValue_Queryable_CanDisallowNull()
 {
     var data = new[]
     {
         new EmailAddress { Value = FakeData.Email(), },
         new EmailAddress { Value = FakeData.Email(), },
         new EmailAddress { Value = FakeData.Email(), },
     };
     data.AsQueryable().ByValue(data[0].Value, false).ShouldNotBeNull();
     var exception = Assert.Throws<InvalidOperationException>(() =>
         data.AsQueryable().ByValue(FakeData.Email(), false));
     Assert.NotNull(exception);
     exception.Message.IndexOf("Sequence contains no matching element", StringComparison.CurrentCulture)
         .ShouldEqual(0);
 }
开发者ID:phobos04,项目名称:tripod,代码行数:15,代码来源:QueryEmailAddressesTests.cs

示例8: InlinePropertyOrderByThenBy

        public void InlinePropertyOrderByThenBy()
        {
            var employees = new[] { new Employee { FirstName = "Test", LastName = "User" } };

            var expected = (from employee in employees.AsQueryable()
                            where (employee.FirstName + " " + employee.LastName) == "Test User"
                            orderby (employee.FirstName + " " + employee.LastName)
                            select employee).ThenBy(x => true);

            var actual = (from employee in employees.AsQueryable().Decompile()
                          where employee.FullName == "Test User"
                          orderby employee.FullName 
                          select employee).ThenBy(x => x.IsActive);

            Assert.AreEqual(expected.Expression.ToString(), actual.Expression.ToString());
        }
开发者ID:bensho,项目名称:DelegateDecompiler,代码行数:16,代码来源:QueryableExtensionsTests.cs

示例9: InlineExtensionMethodOrderBy

        public void InlineExtensionMethodOrderBy()
        {
            var employees = new[] { new Employee { FirstName = "Test", LastName = "User" } };

            var expected = (from employee in employees.AsQueryable()
                            where (employee.FirstName + " " + employee.LastName) == "Test User"
                            orderby (employee.FirstName + " " + employee.LastName)
                            select employee);

            var actual = (from employee in employees.AsQueryable().Decompile()
                          where employee.FullName().Computed() == "Test User"
                          orderby employee.FullName ().Computed()
                          select employee);

            Assert.AreEqual(expected.Expression.ToString(), actual.Expression.ToString());
        }
开发者ID:hazzik,项目名称:DelegateDecompiler,代码行数:16,代码来源:QueryableExtensionsTests.cs

示例10: Handler_ReturnsNullRemoteMembership_WhenNotFound_ByUserId

        public void Handler_ReturnsNullRemoteMembership_WhenNotFound_ByUserId()
        {
            var userId = FakeData.Id();
            var otherUserId = FakeData.Id(userId);
            var loginProvider = FakeData.String();
            var providerKey = FakeData.String();
            var userLoginInfo = new UserLoginInfo(loginProvider, providerKey);
            var remoteMemberships = new[]
            {
                new ProxiedRemoteMembership(loginProvider, providerKey)
                    { UserId = otherUserId, },
                new ProxiedRemoteMembership(FakeData.String(), FakeData.String())
                    { UserId = userId, },
            };
            var data = remoteMemberships.AsQueryable();
            var query = new RemoteMembershipByUser(userId, userLoginInfo);
            var dbSet = new Mock<DbSet<RemoteMembership>>(MockBehavior.Strict).SetupDataAsync(data);
            var entities = new Mock<IReadEntities>(MockBehavior.Strict);
            var entitySet = new EntitySet<RemoteMembership>(dbSet.Object, entities.Object);
            entities.Setup(x => x.Query<RemoteMembership>()).Returns(entitySet);
            var handler = new HandleRemoteMembershipByUserQuery(entities.Object);

            RemoteMembership result = handler.Handle(query).Result;

            result.ShouldBeNull();
            entities.Verify(x => x.Query<RemoteMembership>(), Times.Once);
        }
开发者ID:phobos04,项目名称:tripod,代码行数:27,代码来源:RemoteMembershipByUserTests.cs

示例11: ShouldReturnAllUnfinishedPackagesOfTheRequestedIds

        public void ShouldReturnAllUnfinishedPackagesOfTheRequestedIds()
        {
            const string requestedId1 = "MySuperPackageId";
            const string requestedId2 = "MyOtherPackageId";
            const string requestedId3 = "AnotherPackage";
            var expectedPackage1 = new Package { Id = requestedId1, Version = "5.88.8" };
            var expectedPackage2 = new Package { Id = requestedId2, Version = "1.5.35" };
            var unexpectedPackage1 = new Package { Id = requestedId3, Version = "7.8.9" };
            var unexpectedPackage2 = new Package { Id = requestedId2, Version = "66.88.8" };

            var packages = new[]
            {
                expectedPackage2,
                new Package { Id = "SomePackage", Version = "3.4.5" },
                expectedPackage1,
                unexpectedPackage2,
                unexpectedPackage1,
            };
            var publishedPackages = new[]
            {
                new PublishedPackage { Id = unexpectedPackage2.Id, Version = unexpectedPackage2.Version },
                new PublishedPackage { Id = unexpectedPackage1.Id, Version = unexpectedPackage1.Version },
            };
            _mockedPackageRepository.SetupGet(pr => pr.Collection).Returns(packages.AsQueryable());
            _mockedPublishedPackageRepository.SetupGet(ppr => ppr.Collection).Returns(publishedPackages.AsQueryable());

            var unfinishedPackages = _unfinishedPackageGetter.GetUnfinishedPackages(Guid.NewGuid().ToString(), new[] { requestedId1, requestedId2, requestedId3 });

            CollectionAssert.Contains(unfinishedPackages, expectedPackage1, "Expected Package should have been returned.");
            CollectionAssert.Contains(unfinishedPackages, expectedPackage2, "Expected Package should have been returned.");
            CollectionAssert.DoesNotContain(unfinishedPackages, unexpectedPackage1, "Package should not have been returned since it was in the Feed.");
            CollectionAssert.DoesNotContain(unfinishedPackages, unexpectedPackage2, "Package should not have been returned since it was in the Feed.");
        }
开发者ID:dioptre,项目名称:nkd,代码行数:33,代码来源:GetUnfinishedPackagesTester.cs

示例12: TestSelectMany

 public void TestSelectMany()
 {
     var it = new A { Property = new[] { new B { a = 1, b = "pwic" } } };
     var them = new[] { it };
     Assert.AreEqual(them.SelectMany(x => x.Property, (x, p) => p.a).Count(x => x == 1),
         them.AsQueryable().SelectMany(typeof(A), typeof(B), typeof(int), (Expression<Func<A, IEnumerable<B>>>)(x => x.Property), (Expression<Func<A, B, int>>)((x, p) => p.a)).Cast<int>().Count(x => x == 1));
 }
开发者ID:npenin,项目名称:thewheel-dotnet,代码行数:7,代码来源:TestReflectionExpressions.cs

示例13: WhereEqualStPropertySuccess

 public void WhereEqualStPropertySuccess()
 {
     var ar = new[] { new Helper { Value = 1 }, new Helper { Value = 2 }, new Helper { Value = 3 } };
     var e = ExpressionUtils.GetWhereEqualExpression<Helper>("Value", 2);
     var res = ar.AsQueryable().Where(e).ToArray();
     Assert.AreEqual(res.Length, 1);
     Assert.AreEqual(res[0].Value, 2);
 }
开发者ID:sergey-prokofiev,项目名称:sp-tools,代码行数:8,代码来源:ExpressionsWhereEqualsTests.cs

示例14: TestPocoTypeMapping

        public void TestPocoTypeMapping()
        {
            var products = new[]
            {
                new Product {Id = Guid.NewGuid(), Title = "ProductA", CreatedUser = new User {Name = "UserA"}},
                new Product {Id = Guid.NewGuid(), Title = "ProductB", CreatedUser = null},
            };

            var resultQuery = products.AsQueryable().Project().To<ProductDTO>();
            var expectedQuery = from Param_0 in products.AsQueryable()
                                select new ProductDTO
                                {
                                    Id = Param_0.Id,
                                    Title = Param_0.Title,
                                    CreatedUserName = Param_0.CreatedUser.Name,
                                };
            resultQuery.ToString().ShouldEqual(expectedQuery.ToString());
        }
开发者ID:xcolon,项目名称:Mapster,代码行数:18,代码来源:WhenProjecting.cs

示例15: ByValue_Queryable_CanAllowNull

 public void ByValue_Queryable_CanAllowNull()
 {
     var data = new[]
     {
         new EmailAddress { Value = FakeData.Email(), },
         new EmailAddress { Value = FakeData.Email(), },
         new EmailAddress { Value = FakeData.Email(), },
     };
     data.AsQueryable().ByValue(FakeData.Email()).ShouldBeNull();
 }
开发者ID:phobos04,项目名称:tripod,代码行数:10,代码来源:QueryEmailAddressesTests.cs


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