When to use IQueryable as Return type in web service

Pavan Gawade

If defined return type as IQueryable then my ajax call fail some time.

        [HttpGet]
    public IQueryable<Banner> GetBannerForExcel()
    {
        return this._banneruow.Repository.GetAll();
    }

I am getting 500 Internal Server Error and unable to debug also;

XML Parsing Error: no element found Location: moz-nullprincipal:{4acaf0ef-4230-404d-ae26-304916e1c044} Line Number 1, Column 1:

So when I use return type List<Banner> it works perfect without error.

Vlad Bezden

If your controller returns OData format, the response body from your action that returns IQueryable will contain more information such as next page of data, odata metadata. IQueryable supports further filtering, paging, but it doesn't support random access via indexer. List supports random access via indexer and doesn't support further filtering. In your case if you need only data on the client side then return List or IEnumerable.

IQueryable is better choice for data-tier (server side), because it defer execution.

I also would recommend you to trace what you are getting back from a server when you use IQueryable and List using browser dev tools, or Fiddler

You can find more information here:

IQueryable, IEnumerable or List

Implement Efficient Data Paging

To return IQueryable or not return IQueryable

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

When to use web api instead of dependency injection in a Service Oriented Architecture

分類Dev

how use only higher-order functions to check if the return of web service is null using Optional and avoid noSuchElementException

分類Dev

Azure Functions return IQueryable

分類Dev

When to use 'return' in javascript

分類Dev

WEB API IQueryable skip()take()

分類Dev

When to use Type Constraints in Swift?

分類Dev

Return DataTable schema beside data, in web service output

分類Dev

C# DateTime type over web service with PHP & SOAP

分類Dev

Web API does not serialize bool return type as a json boolean value

分類Dev

What should be the return type of WEB API Action Method?

分類Dev

Support both JSON and XML as return type in Web API 2

分類Dev

how to use WebAPI by creating an instance of it like ASMX web service

分類Dev

How can I use SOAP web service on REST App

分類Dev

When to use unwrapped optionals as part of a type definition

分類Dev

When to use type parameters within Scala?

分類Dev

XSLT error when adding accumulator logic to Web-service Request

分類Dev

How can I retrieve the return type of a function to use in a template?

分類Dev

How to use generics to return all objects for specific type of NSManagedObject?

分類Dev

Use a function's return type as for another template function call

分類Dev

When use Bounded type parameter or type Interface directly

分類Dev

If will an IF statement return when we compare a NSString and a BOOL type variable

分類Dev

file download is damaged when use observe: response in angular service

分類Dev

In simple terms, When do we use service and when do we use directives in angularjs?

分類Dev

Why do return expressions use semicolons when they're unnecessary?

分類Dev

C# unsupported grant type when calling web api

分類Dev

Cannot use errors.New("something wrong") (type error) as type error in return argument

分類Dev

Why is move constructor not picked when returning a local object of type derived from the function's return type?

分類Dev

Issue related to IQueryable method (Cannot implicitly cast type 'long?' to 'long'

分類Dev

415 Unsupported Media Type while invoking RESTful java web service through ajax

Related 関連記事

  1. 1

    When to use web api instead of dependency injection in a Service Oriented Architecture

  2. 2

    how use only higher-order functions to check if the return of web service is null using Optional and avoid noSuchElementException

  3. 3

    Azure Functions return IQueryable

  4. 4

    When to use 'return' in javascript

  5. 5

    WEB API IQueryable skip()take()

  6. 6

    When to use Type Constraints in Swift?

  7. 7

    Return DataTable schema beside data, in web service output

  8. 8

    C# DateTime type over web service with PHP & SOAP

  9. 9

    Web API does not serialize bool return type as a json boolean value

  10. 10

    What should be the return type of WEB API Action Method?

  11. 11

    Support both JSON and XML as return type in Web API 2

  12. 12

    how to use WebAPI by creating an instance of it like ASMX web service

  13. 13

    How can I use SOAP web service on REST App

  14. 14

    When to use unwrapped optionals as part of a type definition

  15. 15

    When to use type parameters within Scala?

  16. 16

    XSLT error when adding accumulator logic to Web-service Request

  17. 17

    How can I retrieve the return type of a function to use in a template?

  18. 18

    How to use generics to return all objects for specific type of NSManagedObject?

  19. 19

    Use a function's return type as for another template function call

  20. 20

    When use Bounded type parameter or type Interface directly

  21. 21

    If will an IF statement return when we compare a NSString and a BOOL type variable

  22. 22

    file download is damaged when use observe: response in angular service

  23. 23

    In simple terms, When do we use service and when do we use directives in angularjs?

  24. 24

    Why do return expressions use semicolons when they're unnecessary?

  25. 25

    C# unsupported grant type when calling web api

  26. 26

    Cannot use errors.New("something wrong") (type error) as type error in return argument

  27. 27

    Why is move constructor not picked when returning a local object of type derived from the function's return type?

  28. 28

    Issue related to IQueryable method (Cannot implicitly cast type 'long?' to 'long'

  29. 29

    415 Unsupported Media Type while invoking RESTful java web service through ajax

ホットタグ

アーカイブ