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


C# List.AsQueryable方法代码示例

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


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

示例1: GetAllProducts

        public IEnumerable<Product> GetAllProducts()
        {
            string sqlExecute = string.Empty;
            List<Product> ProductList = new List<Product>();
            try
            {
                #region SQL 語法

                sqlExecute = @"select * from Product ";

                #endregion SQL 語法

                #region SQL 執行
                using (var conn = SQLFunc.OpenConnection(DBList.Test))
                {
                   ProductList= conn.Query<Product>(sqlExecute).ToList();
                }
                var builder = new ODataConventionModelBuilder() { Namespace = "Default" };
                builder.EntitySet<Product>("Products");
                var model = builder.GetEdmModel();
                return ProductList.AsQueryable();

                #endregion
            }
            catch (Exception ex)
            {

            }
            return ProductList.AsQueryable();
        }
开发者ID:BearBecky,项目名称:GitTest,代码行数:30,代码来源:TestODataController.cs

示例2: Create

        public static IRepository<WorkLog> Create()
        {
            var logsList = new List<WorkLog>();

            for (int i = 1; i < 20; i++)
            {
                logsList.Add(new WorkLog
                {
                    Id = i,
                    ShortDescription = "Log short Description " + i,
                    StartTime = DateTime.Now
                });
            }

            logsList.Add(new WorkLog
            {
                Id = 25,
                ShortDescription = "Log short Description " + 25,
                StartTime = DateTime.Now,
                EndTime = DateTime.Now.AddHours(2)
            });

            var repo = new Mock<IRepository<WorkLog>>();
            repo.Setup(x => x.All()).Returns(logsList.AsQueryable());
            repo.Setup(x => x.Find(It.IsAny<Expression<Func<WorkLog, bool>>>()))
                .Returns<Expression<Func<WorkLog, bool>>>(id => logsList.AsQueryable().Where(id));
            repo.Setup(x => x.Update(It.IsAny<WorkLog>())).Verifiable();

            return repo.Object;
        }
开发者ID:Pip3r4o,项目名称:WebApi-ClockItNow,代码行数:30,代码来源:WorkLogsRepositoryMock.cs

示例3: GetPostsService

        public static IPostsService GetPostsService()
        {
            var post = new Post
            {
                Content = "test post",
                Id = 1,
                PostDate = new DateTime(2015, 11, 1),
                ThreadId = 1,
                UserId = "id1",
                User = new User { Nickname = "testuser" },
                Thread = new Thread { Title = "testTitle" },
                Comments = new List<Comment>(),
                Votes = new List<Vote>()
            };
            var posts = new List<Post>()
            {
                post
            };

            var postsService = new Mock<IPostsService>();
            postsService.Setup(p => p.Add(It.IsAny<string>(), It.Is<int>(t => t > 100), It.IsAny<string>())).Throws<ArgumentException>();
            postsService.Setup(p => p.Add(It.IsAny<string>(), It.Is<int>(t => t < 100), It.IsAny<string>())).Returns(1);
            postsService.Setup(p => p.GetById(It.IsAny<int>())).Returns(post);
            postsService.Setup(p => p.GetByThread(It.IsAny<int>())).Returns(posts.AsQueryable());
            postsService.Setup(p => p.GetByUser(It.Is<string>(s => s != "not exist"))).Returns(posts.AsQueryable());
            postsService.Setup(p => p.GetByUser(It.Is<string>(s => s == "not exist"))).Throws<ArgumentException>();
            postsService.Setup(p => p.Update(It.IsAny<int>(), It.IsAny<string>())).Verifiable();

            return postsService.Object;
        }
开发者ID:DimitarDKirov,项目名称:Forum-Paulo-Coelho,代码行数:30,代码来源:TestObjectsFactory.cs

示例4: Waypoints

        public async Task<IHttpActionResult> Waypoints(int id)
        {
            Mission mission = await db.Missions.FindAsync(id);
            if (mission == null)
            {
                return BadRequest();
            }
            var wps = mission.Waypoints;
            List<Waypoint> wpsInOrder = new List<Waypoint>();
            if (wps.Count == 0)
            {
                return Ok(wpsInOrder.AsQueryable());
            }
            var activeWps = from wp in mission.Waypoints
                            where wp.IsActive
                            select wp;
            var tail = activeWps.First(wp => wp.NextWaypoint == null && wp.IsActive);
            wpsInOrder.Add(tail);
            foreach (var wp in activeWps)
            {
                if (wp.Id == tail.Id)
                {
                    //This is already in the list we don't want to insert it.
                    continue;
                }
                var next = wp.NextWaypoint;
                int index = next != null ? wpsInOrder.FindIndex(n => n.Id == next.Id) : -1;
                if (index == -1)
                {
                    //The next waypoint of this waypoint is not in this list, just insert it behind the last waypoint.
                    int len = wpsInOrder.Count;
                    wpsInOrder.Insert(len - 1, wp);
                }
                else
                {
                    //Insert the waypoint behind its next waypoint.
                    wpsInOrder.Insert(index, wp);
                }

            }

            var diffType = from wp in wpsInOrder.AsQueryable()
                           select new
                           {
                               MissionId = wp.MissionId,
                               NextWaypointId = wp.NextWaypointId,
                               Latitude = wp.Latitude,
                               Longitude = wp.Longitude,
                               Altitude = wp.Altitude,
                               IsActive = wp.IsActive,
                               Id = wp.Id,
                               TimeCompleted = wp.TimeCompleted,
                               WaypointName = wp.WaypointName,
                               Action = wp.Action,
                               GeneratedBy = wp.GeneratedBy,
                           };


            return Ok(diffType);
        }
开发者ID:dragosguta,项目名称:NEST-App,代码行数:60,代码来源:MissionsController.cs

示例5: BuildKeyList

        public static List<Key> BuildKeyList(List<String[]> ParsedPrefix, List<String[]> ParsedSuffix, List<Family> FamilyList)
        {
            List<Key> ret = new List<Key>();

            foreach(String[] thisKeyPrefix in ParsedPrefix)
            {
                if (thisKeyPrefix.Length != 2)
                    throw new Exception();
                foreach(String[] thisKeySuffix in ParsedSuffix)
                {
                    if (thisKeySuffix.Length < 2 || thisKeySuffix.Length > 3)
                        throw new Exception();

                    Family Family2 = null;
                    if (thisKeySuffix.Length == 3)
                        Family2 = FamilyList.AsQueryable().Where(x => x.Name == thisKeySuffix[2]).First();

                    ret.Add
                    (
                        new Key
                        (
                            String.Format("{0}{1}", thisKeyPrefix[0], thisKeySuffix[0]),
                            Int32.Parse(thisKeyPrefix[1]),
                            FamilyList.AsQueryable().Where(x => x.Name == thisKeySuffix[1]).First(),
                            Family2
                        )
                    );
                }
            }

            return ret;
        }
开发者ID:tstarboy,项目名称:DQMInfo,代码行数:32,代码来源:Key.cs

示例6: GetAllCoursesForUser

        public IQueryable<Course> GetAllCoursesForUser(string id)
        {
            var specialty = this.specialtiesRepository
                .All()
                .Where(s => s.Students.Any(std => std.Id == id))
                .Include(s => s.Semesters)
                .FirstOrDefault();

            var courses = new List<Course>();

            if (specialty == null)
            {
                return courses.AsQueryable();
            }

            foreach (var item in specialty.Semesters)
            {
                foreach (var e in item.Courses)
                {
                    courses.Add(e);
                }
            }

            return courses.AsQueryable();
        }
开发者ID:M-Yankov,项目名称:UniversityStudentSystem,代码行数:25,代码来源:SpecialtiesService.cs

示例7: BuildBreedList

        public static List<Breed> BuildBreedList(List<String[]> ParsedCSV, List<Monster> MonsterList, List<Family> FamilyList)
        {
            List<Breed> ret = new List<Breed>();

            foreach(String[] thisBreed in ParsedCSV)
            {
                if (thisBreed.Length < 3 || thisBreed.Length > 4)
                    throw new Exception();

                //check if there is a required depth (+x) for this breed to succeed
                int? thisRequiredDepth = null;
                if (thisBreed.Length == 4)
                    thisRequiredDepth = Int32.Parse(thisBreed[3]);

                IBreedable thisParent1;
                //create first parent (either family or monster)
                if(thisBreed[1].StartsWith("*") && thisBreed[1].EndsWith("*"))
                {
                    //this parent is any member of the specified family
                    thisParent1 = FamilyList.AsQueryable().Where(x => x.Name.ToUpper() == thisBreed[1].TrimStart('*').TrimEnd('*')).First();
                }
                else
                {
                    thisParent1 = MonsterList.AsQueryable().Where(x => x.Name.ToUpper() == thisBreed[1].ToUpper()).First();
                }

                IBreedable thisParent2;
                //create second parent (either family or monster)
                if(thisBreed[2].StartsWith("*") && thisBreed[2].EndsWith("*"))
                {
                    //this parent is any member of the specified family
                    thisParent2 = FamilyList.AsQueryable().Where(x => x.Name.ToUpper() == thisBreed[2].TrimStart('*').TrimEnd('*')).First();
                }
                else
                {
                    thisParent2 = MonsterList.AsQueryable().Where(x => x.Name.ToUpper() == thisBreed[2].ToUpper()).First();
                }

                ret.Add
                (
                    new Breed
                    (
                        MonsterList.AsQueryable().Where(x => x.Name.ToUpper() == thisBreed[0]).First(),
                        thisParent1,
                        thisParent2,
                        thisRequiredDepth
                    )
                );
            }

            return ret;
        }
开发者ID:tstarboy,项目名称:DQMInfo,代码行数:52,代码来源:Breed.cs

示例8: GenericSorter

		protected static List<BaseComparer>  GenericSorter (List<BaseComparer> list)
		{
			BaseComparer bc = list[0];
			SortColumn  scc = bc.ColumnCollection[0] as SortColumn;
			ListSortDirection sd = scc.SortDirection;
			List<BaseComparer> lbc = null;
			if (sd == ListSortDirection.Ascending) {
				lbc = list.AsQueryable().AscendingOrder().ToList();
			} else {

				lbc = list.AsQueryable().DescendingOrder().ToList();
			}
			return lbc;
		}
开发者ID:OmerRaviv,项目名称:SharpDevelop,代码行数:14,代码来源:BaseListStrategy.cs

示例9: LoadParts

        private IQueryable<ComposablePartDefinition> LoadParts()
        {
            if (!Directory.Exists(_dir))
            {
                return (new ComposablePartDefinition[0]).AsQueryable();
            }

            var parts = new List<ComposablePartDefinition>();

            foreach(var file in Directory.GetFiles(this._dir, "*.dll"))
            {
                try
                {
                    var assembly = Assembly.LoadFrom(file);

                    using(var catalog = new AssemblyDiscoveryCatalog(assembly))
                    {
                        parts.AddRange(catalog.Parts);
                    }
                }
                catch (Exception)
                {
                    // TODO: we should log or trace
                }
            }

            return parts.AsQueryable();
        }
开发者ID:chrisortman,项目名称:Ketchup.Web,代码行数:28,代码来源:DirectoryDiscoveryCatalog.cs

示例10: Configure

        public virtual void Configure(IEngine engine, ContainerManager containerManager, EventBroker broker, SmartStoreConfig configuration)
        {
            //other dependencies
            containerManager.AddComponentInstance<SmartStoreConfig>(configuration, "sm.configuration");
            containerManager.AddComponentInstance<IEngine>(engine, "sm.engine");
            containerManager.AddComponentInstance<ContainerConfigurer>(this, "sm.containerConfigurer");

            //type finder
            containerManager.AddComponent<ITypeFinder, WebAppTypeFinder>("sm.typeFinder");

            //register dependencies provided by other assemblies
            var typeFinder = containerManager.Resolve<ITypeFinder>();
            containerManager.UpdateContainer(x =>
            {
                var drTypes = typeFinder.FindClassesOfType<IDependencyRegistrar>();
                var drInstances = new List<IDependencyRegistrar>();
                foreach (var drType in drTypes)
                    drInstances.Add((IDependencyRegistrar)Activator.CreateInstance(drType));
                //sort
                drInstances = drInstances.AsQueryable().OrderBy(t => t.Order).ToList();
                foreach (var dependencyRegistrar in drInstances)
                    dependencyRegistrar.Register(x, typeFinder);
            });

            // event broker
            containerManager.AddComponentInstance(broker);

			// AutofacDependencyResolver
			var scopeProvider = new AutofacLifetimeScopeProvider(containerManager.Container);
			var dependencyResolver = new AutofacDependencyResolver(containerManager.Container, scopeProvider);
			DependencyResolver.SetResolver(dependencyResolver);
        }
开发者ID:GloriousOnion,项目名称:SmartStoreNET,代码行数:32,代码来源:ContainerConfigurer.cs

示例11: FakeCeremony

        /// <summary>
        /// Fakes the ceremony.
        /// </summary>
        /// <param name="count">The count.</param>
        /// <param name="ceremonyRepository">The ceremony repository.</param>
        /// <param name="specificCeremonies">The specific ceremonies.</param>
        public static void FakeCeremony(int count, IRepository<Ceremony> ceremonyRepository, List<Ceremony> specificCeremonies)
        {
            var ceremonies = new List<Ceremony>();
            var specificTransactionsCount = 0;
            if (specificCeremonies != null)
            {
                specificTransactionsCount = specificCeremonies.Count;
                for (int i = 0; i < specificTransactionsCount; i++)
                {
                    ceremonies.Add(specificCeremonies[i]);
                }
            }

            for (int i = 0; i < count; i++)
            {
                ceremonies.Add(CreateValidEntities.Ceremony(i + specificTransactionsCount + 1));
            }

            var totalCount = ceremonies.Count;
            for (int i = 0; i < totalCount; i++)
            {
                ceremonies[i].SetIdTo(i + 1);
                int i1 = i;
                ceremonyRepository
                    .Expect(a => a.GetNullableById(i1 + 1))
                    .Return(ceremonies[i])
                    .Repeat
                    .Any();
            }
            ceremonyRepository.Expect(a => a.GetNullableById(totalCount + 1)).Return(null).Repeat.Any();
            ceremonyRepository.Expect(a => a.Queryable).Return(ceremonies.AsQueryable()).Repeat.Any();
            ceremonyRepository.Expect(a => a.GetAll()).Return(ceremonies).Repeat.Any();
        }
开发者ID:ucdavis,项目名称:Commencement,代码行数:39,代码来源:ControllerRecordFakes.cs

示例12: EmptyDataSource

 public JsonResult EmptyDataSource()
 {
     var people = new List<Person>();
     people.Add(new Person { LastName = "Alone", FirstName = "All" });
     var dataSource = KendoUiHelper.ParseGridData<Person>(people.AsQueryable());
     return Json(dataSource, JsonRequestBehavior.AllowGet);
 }
开发者ID:sympletech,项目名称:SympleLib,代码行数:7,代码来源:KendoGridController.cs

示例13: getSampleCallerTypes

        public static IQueryable<RequestorType> getSampleCallerTypes()
        {
            var requestor0 = new RequestorType {
                RequestorTypeID = 0,
                Code = "ADMIN",
                Value = "Administrator",
                Active = true
            };

            var requestor1 = new RequestorType {
                RequestorTypeID = 1,
                Code = "DRUG CO",
                Value = "Drug Company",
                Active = false
            };

            var requestor2 = new RequestorType {
                RequestorTypeID = 2,
                Code = "FAMILY",
                Value = "Family Members",
                Active = false
            };

            var sampleCallers = new List<RequestorType> {
                requestor0,
                requestor1,
                requestor2
            };

            return sampleCallers.AsQueryable();
        }
开发者ID:vladzaharia,项目名称:cairs,代码行数:31,代码来源:Samples.cs

示例14: FindTypes

        public static IEnumerable<Type> FindTypes(TypeIncludes flags, Type baseType)
        {
            if (baseType == null) throw new ArgumentNullException("baseType", "Must be set to a type");

            Func<Type, bool> predicate = BuildPredicate(flags);
            var foundTypes = from containedType in FindTypes(baseType)
                             where predicate(containedType)
                             select containedType;

            if (!(IsSet(flags, TypeIncludes.ConcreteTypes) && IsConcreteType(baseType)))
            {
                if(foundTypes.Contains(baseType))
                {
                    IList<Type> b = new List<Type>();
                    b.Add(baseType);
                    foundTypes = foundTypes.Except(b.AsQueryable());
                }
            }
            
            if (IsSet(flags, TypeIncludes.PrimitiveTypes))
            {
                foundTypes = foundTypes.Concat(FindPrimitiveTypes());
            }
            return foundTypes;
        }
开发者ID:DBailey635,项目名称:C1-CMS,代码行数:25,代码来源:TypeLocator.cs

示例15: Index

        //[Route("~/")]
        //[Route("")]
        public ActionResult Index()
        {
            List<ArticleModel> articles = new List<ArticleModel>();
            user = (Users)Session["User"];
            // if (ModelState.IsValid)
            // {
            ConnManager connManager = new ConnManager();
            if(user!= null && user.UserId == 1)
                articles = connManager.GetArticles("Select * from VwArticles order by articleId desc");
            else
                articles = connManager.GetArticles("Select * from VwArticles where IsDisplay =1 order by articleId desc");

            // }

            PagingInfo info = new PagingInfo();
            info.SortField = " ";
            info.SortDirection = " ";
            info.PageSize = 7;
            info.PageCount = Convert.ToInt32(Math.Ceiling((double)(articles.Count/info.PageSize)));
            info.CurrentPageIndex = 0;

            // var query = articles.OrderByDescending(c => c.ArticleID).Take(info.PageSize);

            var query = articles.AsQueryable();
            query = query.Skip(info.CurrentPageIndex * info.PageSize).Take(info.PageSize);
            ViewBag.PagingInfo = info;

            return View(query.ToList());
        }
开发者ID:joinpramod,项目名称:MyBlogWebsiteMVC2015,代码行数:31,代码来源:ArticlesController.cs


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