public override void SetUp() { base.SetUp(); _source2 = Expression.Constant(new[] { "test1", "test2" }); _node = new ConcatExpressionNode( CreateParseInfo(SourceNode, "u", ReflectionUtility.GetMethod(() => Queryable.Concat <int> (null, null))), _source2); }
public void Test([DataSources] string context) { using (var db = GetDataContext(context)) { using (db.CreateLocalTable <StLink>()) using (db.CreateLocalTable <StVersion>()) { var parentId = 111; var query = from u in Queryable.Concat( from link in db.GetTable <StLink>() where link.InIdParent == parentId select new { VersionId = link.InIdChild, Link = link }, from link in db.GetTable <StLink>() where link.InIdChild == parentId select new { VersionId = link.InIdParent, Link = link }) join version in db.GetTable <StVersion>() on u.VersionId equals version.InId select new { //LinkTypeId = u.Link.RlTypesAndType.InIdLinkType, //LinkId = u.Link.InId, MainId = version.InIdMain }; var _ = query.ToList(); } } }
internal static IQueryable <EntitySet> GetEntitySets() { IQueryable <EntitySet> _entities = new List <EntitySet>().AsQueryable(); foreach (Container container in ContainerRepository.GetAllContainers()) { _entities = Queryable.Concat(_entities, Cache.EntitySets(container.Alias)); } return(_entities); }
public void GetSupportedMethods() { Assert.That( ConcatExpressionNode.GetSupportedMethods(), Is.EquivalentTo( new[] { GetGenericMethodDefinition(() => Queryable.Concat <object> (null, null)), GetGenericMethodDefinition(() => Enumerable.Concat <object> (null, null)) })); }
public async Task <IHttpActionResult> GetFriends(string puserId, string param) { var userId = CurrentUser.UserId; if (puserId != "my") { if (!Int32.TryParse(puserId, out userId)) { return(BadRequest("/api/Friends/List/my/{type} or /api/Friends/List/{userId}/{type}")); } } var rels = subscribeRepository.Objects; var variants = new Dictionary <string, Func <IQueryable <ApplicationUser> > >(); variants["f"] = () => rels.Where(s => s.SubscribedToId == userId && s.Relationship == Relationship.Follow).Select(s => s.Subscriber); variants["s"] = () => rels.Where(s => s.SubscriberId == userId && s.Relationship == Relationship.Follow).Select(s => s.SubscribedTo); variants["m"] = () => Queryable.Concat( rels.Where( s => s.SubscriberId == userId && s.Relationship == Relationship.Friend).Select(s => s.SubscribedTo), rels.Where( s => s.SubscribedToId == userId && s.Relationship == Relationship.Friend).Select(s => s.Subscriber)); //variants["mf"] = () => rels // .Where(s => (s.SubscribedToId == userId && (s.Relationship == Relationship.Follower || s.Relationship == Relationship.Friend))) // .Select(s => s.Subscriber); //variants["ms"] = () => rels // .Where(s => (s.SubscriberId == userId && (s.Relationship == Relationship.Following || s.Relationship == Relationship.Friend))) // .Select(s => s.SubscribedTo); if (!variants.ContainsKey(param)) { return(BadRequest("incorrect input")); } var result = await variants[param]().ToArrayAsync(); return(Ok(result.Select(u => { var photo = photosRepo.Objects.Where(p => p.PhotoId == u.PhotoId).FirstOrDefault(); return new UserProfileViewModel(u, photo, null); }).ToArray())); }
public static IQueryable <T> append <T>(IQueryable <T> lhs, IQueryable <T> rhs) => Queryable.Concat(lhs, rhs);
public ActionResult <IEnumerable <ServiceVM> > GetAllService([FromQuery] ServiceSM model, int pageSize, int pageIndex, bool withRateScore, string searchQuery) { IQueryable <Service> serviceList = _service.GetAll(s => s.ServiceType, s => s.Gallery.Images, s => s.Account.Gallery.Images); IQueryable <Service> serviceBasedOnSearchQuery; IQueryable <Service> result = null; if (!string.IsNullOrEmpty(searchQuery)) { var serviceByServiceName = serviceList.Where(_ => _.ServiceName.Contains(searchQuery)); var serviceByProviderName = serviceList.Where(_ => _.Account.DisplayName.Contains(searchQuery)); var serviceByServiceTypeName = serviceList.Where(_ => _.ServiceType.Name.Contains(searchQuery)); serviceBasedOnSearchQuery = Queryable.Concat(serviceByServiceName, serviceByProviderName); result = Queryable.Concat(serviceBasedOnSearchQuery, serviceByServiceTypeName); } if (!string.IsNullOrEmpty(model.Description)) { serviceList = serviceList.Where(s => s.Description.Contains(model.Description)); } if (!string.IsNullOrEmpty(model.ServiceName)) { serviceList = serviceList.Where(s => s.ServiceName.Contains(model.ServiceName)); } if (model.CreatedAtMin.HasValue) { serviceList = serviceList.Where(s => s.CreatedDate >= model.CreatedAtMin); } if (model.CreatedAtMax.HasValue) { serviceList = serviceList.Where(s => s.CreatedDate <= model.CreatedAtMax); } if (model.UpdatedAtMin.HasValue) { serviceList = serviceList.Where(s => s.UpdatedDate >= model.UpdatedAtMin); } if (model.UpdatedAtMax.HasValue) { serviceList = serviceList.Where(s => s.UpdatedDate <= model.UpdatedAtMax); } if (model.LowerPrice > 0) { serviceList = serviceList.Where(s => s.Price >= model.LowerPrice); } if (model.UpperPrice > 0) { serviceList = serviceList.Where(s => s.Price <= model.UpperPrice); } if (model.LowerTime > 0) { serviceList = serviceList.Where(s => s.EstimateTime >= model.LowerTime); } if (model.UpperTime > 0) { serviceList = serviceList.Where(s => s.EstimateTime <= model.UpperTime); } if (model.AccountId != 0) { serviceList = serviceList.Where(s => s.AccountId == model.AccountId); } if (model.ServiceTypeId != 0) { serviceList = serviceList.Where(s => s.ServiceTypeId == model.ServiceTypeId); } if (model.Status == true) { serviceList = serviceList.Where(s => s.Status.Equals("Active")); } if (model.GalleryId != 0) { serviceList = serviceList.Where(s => s.GalleryId == model.GalleryId); } if (pageSize == 0) { pageSize = 20; } if (pageIndex == 0) { pageIndex = 1; } Paged <ServicePagingSM> pagedModel = null; if (string.IsNullOrEmpty(searchQuery)) { pagedModel = _pagingSupport.From(serviceList) .GetRange(pageIndex, pageSize, s => s.Id) .Paginate <ServicePagingSM>(); } else { pagedModel = _pagingSupport.From(result.Distinct()) .GetRange(pageIndex, pageSize, s => s.UpdatedDate) .Paginate <ServicePagingSM>(); } if (withRateScore) { pagedModel.Content = pagedModel.Content.AsEnumerable().Select <ServicePagingSM, ServicePagingSM>(_ => { var rating = _feedbackService.GetRateScoreByService(_.Id); _.RateScore = rating[0]; _.TotalFeedback = (int)rating[1]; return(_); }).AsQueryable(); } return(Ok(pagedModel)); }
public static void Init() { _map = new Dictionary <MethodInfo, MethodInfo>(); _enumerableMethods = new HashSet <MethodInfo>(); //Some dummy objects of specific types. They help us to denote a specific overload of Queryable and Enumerable methods, // when we call 'Add'. The 'Add' method accepts two expressions as parameters, and it extracts the matching Queryable/Enumerable // methods from these expressions, and add the pair to the Map dictionary. // We use dummy classes TSource, TKey, etc - defined below. IQueryable <TSource> qS = null; IOrderedQueryable <TSource> qSord = null; IEnumerable <TSource> eS = null; IOrderedEnumerable <TSource> eSord = null; TSource objS = null; TKey objK = null; TKeyComparer objKComp = null; TSourceComparer objSComp = null; TElement objEl = null; //Aggregate Add(() => Queryable.Aggregate(qS, (s, ss) => objS), () => Enumerable.Aggregate(eS, (s, ss) => objS)); Add(() => Queryable.Aggregate(qS, objEl, (el, s) => objEl), () => Enumerable.Aggregate(eS, objEl, (el, s) => objEl)); Add(() => Queryable.Aggregate(qS, objEl, (el, s) => objEl, x => 0), () => Enumerable.Aggregate(eS, objEl, (el, s) => objEl, x => 0)); //All, Any Add(() => Queryable.All(qS, s => true), () => Enumerable.All(eS, s => true)); Add(() => Queryable.Any(qS), () => Enumerable.Any(eS)); Add(() => Queryable.Any(qS, s => true), () => Enumerable.Any(eS, s => true)); // Average Add(() => Queryable.Average(QueryOf <decimal>()), () => Enumerable.Average(QueryOf <decimal>())); Add(() => Queryable.Average(QueryOf <decimal?>()), () => Enumerable.Average(QueryOf <decimal?>())); Add(() => Queryable.Average(QueryOf <double>()), () => Enumerable.Average(QueryOf <double>())); Add(() => Queryable.Average(QueryOf <double?>()), () => Enumerable.Average(QueryOf <double?>())); Add(() => Queryable.Average(QueryOf <float>()), () => Enumerable.Average(QueryOf <float>())); Add(() => Queryable.Average(QueryOf <float?>()), () => Enumerable.Average(QueryOf <float?>())); Add(() => Queryable.Average(QueryOf <int>()), () => Enumerable.Average(QueryOf <int>())); Add(() => Queryable.Average(QueryOf <int?>()), () => Enumerable.Average(QueryOf <int?>())); Add(() => Queryable.Average(QueryOf <long>()), () => Enumerable.Average(QueryOf <long>())); Add(() => Queryable.Average(QueryOf <long?>()), () => Enumerable.Average(QueryOf <long?>())); Add(() => Queryable.Average(qS, x => (decimal)0), () => Enumerable.Average(eS, x => (decimal)0)); Add(() => Queryable.Average(qS, x => (decimal?)0), () => Enumerable.Average(eS, x => (decimal?)0)); Add(() => Queryable.Average(qS, x => (double)0), () => Enumerable.Average(eS, x => (double)0)); Add(() => Queryable.Average(qS, x => (double?)0), () => Enumerable.Average(eS, x => (double?)0)); Add(() => Queryable.Average(qS, x => (float)0), () => Enumerable.Average(eS, x => (float)0)); Add(() => Queryable.Average(qS, x => (float?)0), () => Enumerable.Average(eS, x => (float?)0)); Add(() => Queryable.Average(qS, x => (int)0), () => Enumerable.Average(eS, x => (int)0)); Add(() => Queryable.Average(qS, x => (int?)0), () => Enumerable.Average(eS, x => (int?)0)); Add(() => Queryable.Average(qS, x => (long)0), () => Enumerable.Average(eS, x => (long)0)); Add(() => Queryable.Average(qS, x => (long?)0), () => Enumerable.Average(eS, x => (long?)0)); //Cast Add(() => Queryable.Cast <TElement>(qS), () => Enumerable.Cast <TElement>(eS)); // Concat Add(() => Queryable.Concat(qS, eS), () => Enumerable.Concat(eS, eS)); //Contains Add(() => Queryable.Contains(qS, objS), () => Enumerable.Contains(eS, objS)); Add(() => Queryable.Contains(qS, objS, objSComp), () => Enumerable.Contains(eS, objS, objSComp)); //Count Add(() => Queryable.Count(qS), () => Enumerable.Count(eS)); Add(() => Queryable.Count(qS, s => true), () => Enumerable.Count(eS, s => true)); //DefaultIfEmpty Add(() => Queryable.DefaultIfEmpty(qS), () => Enumerable.DefaultIfEmpty(eS)); Add(() => Queryable.DefaultIfEmpty(qS, objS), () => Enumerable.DefaultIfEmpty(eS, objS)); //Distinct Add(() => Queryable.Distinct(qS), () => Enumerable.Distinct(eS)); Add(() => Queryable.Distinct(qS, objSComp), () => Enumerable.Distinct(eS, objSComp)); // ElementAt Add(() => Queryable.ElementAt(qS, 0), () => Enumerable.ElementAt(eS, 0)); Add(() => Queryable.ElementAtOrDefault(qS, 0), () => Enumerable.ElementAtOrDefault(eS, 0)); // Except Add(() => Queryable.Except(qS, qS), () => Enumerable.Except(eS, eS)); Add(() => Queryable.Except(qS, qS, objSComp), () => Enumerable.Except(eS, eS, objSComp)); // First Add(() => Queryable.First(qS), () => Enumerable.First(eS)); Add(() => Queryable.First(qS, s => true), () => Enumerable.First(eS, s => true)); Add(() => Queryable.FirstOrDefault(qS), () => Enumerable.FirstOrDefault(eS)); Add(() => Queryable.FirstOrDefault(qS, s => true), () => Enumerable.FirstOrDefault(eS, s => true)); // GroupBy Add(() => Queryable.GroupBy(qS, s => objK), () => Enumerable.GroupBy(eS, s => objK)); Add(() => Queryable.GroupBy(qS, s => objK, (s, ss) => 0), () => Enumerable.GroupBy(eS, s => objK, (s, ss) => 0)); Add(() => Queryable.GroupBy(qS, s => objK, (s) => 0), () => Enumerable.GroupBy(eS, s => objK, (s) => 0)); Add(() => Queryable.GroupBy(qS, s => objS, objSComp), () => Enumerable.GroupBy(eS, s => s, objSComp)); Add(() => Queryable.GroupBy(qS, s => objS, (s, ss) => 0, objSComp), () => Enumerable.GroupBy(eS, s => objS, (s, ss) => 0, objSComp)); Add(() => Queryable.GroupBy(qS, s => objS, s => objK, (s, ss) => 0), () => Enumerable.GroupBy(eS, s => objS, s => objK, (s, ss) => 0)); Add(() => Queryable.GroupBy(qS, s => objK, s => objEl, objKComp), () => Enumerable.GroupBy(eS, s => objK, s => objEl, objKComp)); Add(() => Queryable.GroupBy(qS, s => objS, s => objK, (s, ss) => 0, objSComp), () => Enumerable.GroupBy(eS, s => objS, s => objK, (s, ss) => 0, objSComp)); //GroupJoin IEnumerable <TSource2> eInner = null; Add(() => Queryable.GroupJoin(qS, eInner, s => objK, s => objK, (s, ss) => objEl), () => Enumerable.GroupJoin(eS, eInner, s => objK, s => objK, (s, ss) => objEl)); Add(() => Queryable.GroupJoin(qS, eInner, s => objK, s => objK, (s, ss) => objEl, objKComp), () => Enumerable.GroupJoin(eS, eInner, s => objK, s => objK, (s, ss) => objEl, objKComp)); //Intersect Add(() => Queryable.Intersect(qS, eS), () => Enumerable.Intersect(eS, eS)); Add(() => Queryable.Intersect(qS, eS, objSComp), () => Enumerable.Intersect(eS, eS, objSComp)); // Join Add(() => Queryable.Join(qS, eInner, s => objK, s => objK, (s, ss) => objEl), () => Enumerable.Join(eS, eInner, s => objK, s => objK, (s, ss) => objEl)); Add(() => Queryable.Join(qS, eInner, s => objK, s => objK, (s, ss) => objEl, objKComp), () => Enumerable.Join(eS, eInner, s => objK, s => objK, (s, ss) => objEl, objKComp)); // Last Add(() => Queryable.Last(qS), () => Enumerable.Last(eS)); Add(() => Queryable.Last(qS, s => true), () => Enumerable.Last(eS, s => true)); Add(() => Queryable.LastOrDefault(qS), () => Enumerable.LastOrDefault(eS)); Add(() => Queryable.LastOrDefault(qS, s => true), () => Enumerable.LastOrDefault(eS, s => true)); //LongCount Add(() => Queryable.LongCount(qS), () => Enumerable.LongCount(eS)); Add(() => Queryable.LongCount(qS, s => true), () => Enumerable.LongCount(eS, s => true)); // Max, Min Add(() => Queryable.Max(qS), () => Enumerable.Max(eS)); Add(() => Queryable.Max(qS, s => objEl), () => Enumerable.Max(eS, s => objEl)); //Enumerable has many Max versions - make sure we pick generic one here Add(() => Queryable.Min(qS), () => Enumerable.Min(eS)); Add(() => Queryable.Min(qS, s => objEl), () => Enumerable.Min(eS, s => objEl)); //Enumerable has many Min versions - make sure we pick generic one here // OfType Add(() => Queryable.OfType <TElement>(qS), () => Enumerable.OfType <TElement>(eS)); //have to specify type arg explicitly // OrderBy Add(() => Queryable.OrderBy(qS, (s) => objK), () => Enumerable.OrderBy(eS, (s) => objK)); Add(() => Queryable.OrderBy(qS, (s) => objK, objKComp), () => Enumerable.OrderBy(eS, (s) => objK, objKComp)); Add(() => Queryable.OrderByDescending(qS, (s) => true), () => Enumerable.OrderByDescending(eS, (s) => true)); Add(() => Queryable.OrderByDescending(qS, (s) => objK, objKComp), () => Enumerable.OrderByDescending(eS, (s) => objK, objKComp)); // Reverse Add(() => Queryable.Reverse(qS), () => Enumerable.Reverse(eS)); //Select Add(() => Queryable.Select(qS, (s) => true), () => Enumerable.Select(eS, (s) => true)); Add(() => Queryable.Select(qS, (s, i) => true), () => Enumerable.Select(eS, (s, i) => true)); //SelectMany IEnumerable <TElement> objListOfEl = null; Add(() => Queryable.SelectMany(qS, (s) => objListOfEl), () => Enumerable.SelectMany(eS, (s) => objListOfEl)); Add(() => Queryable.SelectMany(qS, (s, i) => objListOfEl), () => Enumerable.SelectMany(eS, (s, i) => objListOfEl)); Add(() => Queryable.SelectMany(qS, s => objListOfEl, (s, ss) => objEl), () => Enumerable.SelectMany(eS, s => objListOfEl, (s, ss) => objEl)); Add(() => Queryable.SelectMany(qS, (s, i) => objListOfEl, (s, ss) => objEl), () => Enumerable.SelectMany(eS, (s, i) => objListOfEl, (s, ss) => objEl)); // SequenceEqual Add(() => Queryable.SequenceEqual(qS, qS), () => Enumerable.SequenceEqual(eS, eS)); Add(() => Queryable.SequenceEqual(qS, qS, objSComp), () => Enumerable.SequenceEqual(eS, eS, objSComp)); // Single Add(() => Queryable.Single(qS), () => Enumerable.Single(eS)); Add(() => Queryable.Single(qS, s => true), () => Enumerable.Single(eS, s => true)); Add(() => Queryable.SingleOrDefault(qS), () => Enumerable.SingleOrDefault(eS)); Add(() => Queryable.SingleOrDefault(qS, s => true), () => Enumerable.SingleOrDefault(eS, s => true)); // Skip, SkipWhile Add(() => Queryable.Skip(qS, 1), () => Enumerable.Skip(eS, 1)); Add(() => Queryable.SkipWhile(qS, s => true), () => Enumerable.SkipWhile(eS, s => true)); Add(() => Queryable.SkipWhile(qS, (s, i) => true), () => Enumerable.SkipWhile(eS, (s, i) => true)); // Sum Add(() => Queryable.Sum(QueryOf <decimal>()), () => Enumerable.Sum(QueryOf <decimal>())); Add(() => Queryable.Sum(QueryOf <decimal?>()), () => Enumerable.Sum(QueryOf <decimal?>())); Add(() => Queryable.Sum(QueryOf <double>()), () => Enumerable.Sum(QueryOf <double>())); Add(() => Queryable.Sum(QueryOf <double?>()), () => Enumerable.Sum(QueryOf <double?>())); Add(() => Queryable.Sum(QueryOf <float>()), () => Enumerable.Sum(QueryOf <float>())); Add(() => Queryable.Sum(QueryOf <float?>()), () => Enumerable.Sum(QueryOf <float?>())); Add(() => Queryable.Sum(QueryOf <int>()), () => Enumerable.Sum(QueryOf <int>())); Add(() => Queryable.Sum(QueryOf <int?>()), () => Enumerable.Sum(QueryOf <int?>())); Add(() => Queryable.Sum(QueryOf <long>()), () => Enumerable.Sum(QueryOf <long>())); Add(() => Queryable.Sum(QueryOf <long?>()), () => Enumerable.Sum(QueryOf <long?>())); Add(() => Queryable.Sum(qS, x => (decimal)0), () => Enumerable.Sum(eS, x => (decimal)0)); Add(() => Queryable.Sum(qS, x => (decimal?)0), () => Enumerable.Sum(eS, x => (decimal?)0)); Add(() => Queryable.Sum(qS, x => (double)0), () => Enumerable.Sum(eS, x => (double)0)); Add(() => Queryable.Sum(qS, x => (double?)0), () => Enumerable.Sum(eS, x => (double?)0)); Add(() => Queryable.Sum(qS, x => (float)0), () => Enumerable.Sum(eS, x => (float)0)); Add(() => Queryable.Sum(qS, x => (float?)0), () => Enumerable.Sum(eS, x => (float?)0)); Add(() => Queryable.Sum(qS, x => (int)0), () => Enumerable.Sum(eS, x => (int)0)); Add(() => Queryable.Sum(qS, x => (int?)0), () => Enumerable.Sum(eS, x => (int?)0)); Add(() => Queryable.Sum(qS, x => (long)0), () => Enumerable.Sum(eS, x => (long)0)); Add(() => Queryable.Sum(qS, x => (long?)0), () => Enumerable.Sum(eS, x => (long?)0)); // Take, TakeWhile Add(() => Queryable.Take(qS, 1), () => Enumerable.Take(eS, 1)); Add(() => Queryable.TakeWhile(qS, s => true), () => Enumerable.TakeWhile(eS, s => true)); Add(() => Queryable.TakeWhile(qS, (s, i) => true), () => Enumerable.TakeWhile(eS, (s, i) => true)); // ThenBy, ThenByDescending Add(() => Queryable.ThenBy(qSord, (s) => objK), () => Enumerable.ThenBy(eSord, (s) => objK)); Add(() => Queryable.ThenBy(qSord, (s) => objK, objKComp), () => Enumerable.ThenBy(eSord, (s) => objK, objKComp)); Add(() => Queryable.ThenByDescending(qSord, (s) => objK), () => Enumerable.ThenByDescending(eSord, (s) => objK)); Add(() => Queryable.ThenByDescending(qSord, (s) => objK, objKComp), () => Enumerable.ThenByDescending(eSord, (s) => objK, objKComp)); // Union Add(() => Queryable.Union(qS, qS), () => Enumerable.Union(eS, eS)); Add(() => Queryable.Union(qS, qS, objSComp), () => Enumerable.Union(eS, eS, objSComp)); // Where Add(() => Queryable.Where(qS, (s) => true), () => Enumerable.Where(eS, (s) => true)); Add(() => Queryable.Where(qS, (s, i) => true), () => Enumerable.Where(eS, (s, i) => true)); // Zip Add(() => Queryable.Zip(qS, eInner, (s, ss) => objEl), () => Enumerable.Zip(eS, eInner, (s, ss) => objEl)); }