linq allows developers to build a query, which is executed once the full query is built. you can build a query using multiple expressions without making a single call to the database. linq will delay the call until the last possible moment.

in your case, the statement if (giftcard == null) explicitly asks for the object. therefore, a database call will be made to fetch the requested giftcard. secondly, the orderby operation will be performed on the transactions that are already in memory (due to include(g=>g.transactions)). so, no database calls here.

ultimately, your whole code will make only a single database call.

Related Query

More Query from same tag