locked
like tolist() how many functions are there. RRS feed

  • Question

  • User2102072086 posted
    hi,
     
        as tolist() execute the linq query, how can i find that which method executes the query.
    so that i do not have to put tolist every time?
     
    yours sincerley 
    Sunday, March 1, 2020 12:51 PM

All replies

  • User475983607 posted

    as tolist() execute the linq query, how can i find that which method executes the query. so that i do not have to put tolist every time?

    Enumerating (looping) the IQueryable<T> type executes Entity Framework queries.  The fundamentals are covered in the official Querying Data documentation.

    https://docs.microsoft.com/en-us/ef/core/

    https://docs.microsoft.com/en-us/ef/core/querying/

    Sunday, March 1, 2020 1:28 PM
  • User1120430333 posted

    The link should help you. It talks about ToList() and many others.

    https://www.codeproject.com/Articles/286255/Using-LINQ-Queries

    Sunday, March 1, 2020 6:08 PM
  • User-17257777 posted

    Hi rajemessage,

    Common query methods are as follows:

    1. Find()

    When you want to get an item by primary key. This will return null if it can't find an item. It will look in the context before going to the database.

    2. First()

    When you expect one or more items to be returned by a query but you only want to access the first item in your code (ordering could be important in the query here). This will throw an exception if the query does not return at least one item.

    3.Single()

    When you expect exactly one item to be returned by a query. This will throw an exception if the query does not return exactly one item.

    For more details about LINQ-to-Entities queries, you can refer to 

    https://www.entityframeworktutorial.net/querying-entity-graph-in-entity-framework.aspx

    Best Regards,

    Jiadong Meng

    Monday, March 2, 2020 5:42 AM