static void Main(string[] args) { ODataSettings.SetInitializer( s => { s.ValidationSettings.MaxTop = 1000; s.QuerySettings.PageSize = 20; }); GetStartedDemo.Demo(); Console.WriteLine(); FilterDemo.BySimpleProperties(); FilterDemo.ByRelatedEntity(); OrderByDemo.BySimpleProperties(); SelectDemo.OnlyNameField(); ExpandDemo.SelectExpand1(); ExpandDemo.SelectExpand2(); SelectExpandJsonDemo.SelectExpandToJson(); TopSkipDemo.Top5(); TopSkipDemo.Top5Skip5(); TopSkipDemo.DefaultPageSize(); }
private TSelect ApplySelectExpand <TSelect>(TSelect entity, ODataQuerySettings settings) { var result = default(TSelect); SelectExpandClause processedClause = this.SelectExpand.ProcessLevels(); SelectExpandQueryOption newSelectExpand = new SelectExpandQueryOption( this.SelectExpand.RawSelect, this.SelectExpand.RawExpand, this.SelectExpand.Context, processedClause); ODataSettings qsettings = this.Context.RequestContainer.GetRequiredService <ODataSettings>(); newSelectExpand.Validate(qsettings.ValidationSettings); var type = typeof(TSelect); if (type == typeof(IQueryable)) { result = (TSelect)newSelectExpand.ApplyTo((IQueryable)entity, settings); } else if (type == typeof(object)) { result = (TSelect)newSelectExpand.ApplyTo(entity, settings); } return(result); }
public static IQueryable <T> ApplySkipWithValidation <T>(IQueryable <T> query, long?skip, ODataSettings settings) { if (skip.HasValue) { if (skip.Value > int.MaxValue) { throw new ODataException( Error.Format( SRResources.SkipTopLimitExceeded, int.MaxValue, AllowedQueryOptions.Skip, skip.Value)); } if (skip.Value > settings.ValidationSettings.MaxSkip) { throw new ODataException( Error.Format( SRResources.SkipTopLimitExceeded, settings.ValidationSettings.MaxSkip, AllowedQueryOptions.Skip, skip.Value)); } IQueryable <T> result = ExpressionHelpers.Skip( query, (int)skip.Value, typeof(T), settings.QuerySettings.EnableConstantParameterization) as IQueryable <T>; return(result); } return(query); }