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); }