score:2
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.
Source: stackoverflow.com
Related Query
- How can I check the number of calls to the database in LINQ query when using .NET Core and Code First?
- How can I query a database with LINQ when the column is a number but I have a string in the WHERE?
- How can I write the following code more elegantly using LINQ query syntax?
- How can I simplify (speed up) the selecting query from a database that contains more than 1 million records using LINQ
- When using a LINQ Where clause on a Dictionary, how can I return a dictionary of the same type?
- How to use expressions to build a LINQ query dynamically when using an interface to get the column name?
- Using LINQ how can I check for an instance of a number in one array, in another array?
- How can we express the following code using query expression?
- How to get the index of int array when using linq query
- How can I use a predicate in a crm sdk 2011 linq query when the query contains a join?
- LINQ - database query using "into", how do I reference data prior to "into" in the select clause?
- How to dynamically query the database using LINQ and a variable?
- How can I build a LINQ predicate/dynamic.LINQ query based off grid filtering when the grid properties don't have the entity properties?
- Using Linq to XML, how can I select the elements that have exactly x number of parent elements?
- How to GroupBy using LINQ query in C# when the key is to be the same type as your type T when grouping List<T>
- I have a LINQ statement that is partially query and partially method. How can I do this using one or the other?
- how to fetch data from database using linq query for relationship 1:N and N:N (between 3 entity) in asp.net mvc EF code first?
- How can I create a join like query using LINQ and check for a propery in a child object?
- how do i handle value when the value is null or Empty using linq query
- How to check the user already offer the ride using LINQ in NET Core
- How do I find the number of questions with answers in a survey in my database using LINQ
- How can I filter a dictionary using LINQ and return it to a dictionary from the same type
- How to avoid Query Plan re-compilation when using IEnumerable.Contains in Entity Framework LINQ queries?
- Why does C# compiler create private DisplayClass when using LINQ method Any() and how can I avoid it?
- How do I count the number of child collection's items using LINQ Method Syntax?
- How can I sort a string of text followed by a number using LINQ
- How can I trace the query produced by the documentdb Linq provider?
- How to reuse a linq expression for 'Where' when using multiple source tables
- How can I view the Entity Framework LINQ query plan cache?
- How to check if XML contains element when using LINQ to XML?
More Query from same tag
- Select data from tow table using LINQ in Asp Core razor pages
- linq to sql + stackoverflow exception when querying objects
- how to avoid two columns contain 0 in linq
- How to remove duplicates (distinct values) with out primary key
- Unable to compare date in MongoDB
- What is the structure of IQueryable?
- LINQ and dynamic strong types
- Linq with embedded functions
- How to get mismatch position using Linq or lambda operation on two string array
- linq query which will return single values and a list in one call
- c# linq extension Group and select data by quarter with missing months inside
- Entity Framework 4 Unit of Work / Repository WITHOUT .Query() Lambda
- C# Check If List Contains Similiar Strings Using LINQ
- linq2db find string in varchar field
- How to find the first occurrence of a substring in a list of substrings?
- Bind LINQ Query results to Repeater
- Multiple linq "from" and variables visibility
- LINQ Optimization for searching a if an object exist in a list within a list
- Create nested object on Entity Framework Linq query
- Using LINQ query on Dictionary and List
- Gridview sorting in ASP.NET
- Writing a function to filter a list of a items by a property on it's base type in c#
- Difference using joins or navigation properties in EF
- joins in Linq using lists<strings> with no id to index from
- Comparing and Finding row value in DataTable C#
- Advanced LINQ filtering
- How can you use a LINQ Lambda Where Property Count = Something
- SQLite-net TableQuery<T>.Select() poor performance
- Linq query - Tidy Up/Optimization
- EF Core Linq to SQLite could not be translated, works on SQL Server