RunningObjects.Core.Query.Query.GetAppliedQuery C# (CSharp) Method

GetAppliedQuery() private method

private GetAppliedQuery ( ) : IQueryable
return IQueryable
        private IQueryable GetAppliedQuery()
        {
            if (Source != null)
            {
                if (Filter != null)
                    Source = Filter.Apply(Source);

                if (Where != null)
                {
                    RunningObjectsSetup.Configuration.Query.ParseKeywords(this);
                    Source = (Parameters != null && Parameters.Any())
                                 ? Source.Where(Where.Expression, Parameters)
                                 : Source.Where(Where.Expression);
                }

                if (OrderBy != null && OrderBy.Elements.Any())
                {
                    var orderBy = OrderBy.Elements.Aggregate(string.Empty, (current, element) => current + (element.Key + " " + element.Value + ","));
                    Source = Source.OrderBy(orderBy.Substring(0, orderBy.Length - 1));
                }
                else
                {
                    var mapping = ModelMappingManager.MappingFor(ModelType);
                    var descriptor = new ModelDescriptor(mapping);

                    if (descriptor.Properties.Any())
                    {
                        var orderedProperty = descriptor.KeyProperty ??
                                              (descriptor.TextProperty ?? descriptor.Properties.FirstOrDefault());
                        if (orderedProperty != null)
                            Source = Source.OrderBy(orderedProperty.Name + " Asc");
                    }
                }

                if (Skip.HasValue)
                    Source = Source.Skip(Skip.Value);

                if (Take.HasValue)
                    Source = Source.Take(Take.Value);

                if(Select != null && Select.Properties.Any())
                    Source = Source.Select(string.Format("new({0})", Select));
            }
            return Source;
        }