score:2
Accepted answer
It depends. DbSet.SingleOrDefault(<condition>).Attribute
will fetch whole row from database and pass it over the network to you application. So if your table has many columns and/or columns containing a lot of data (big stings, some binary data) then first one should be faster cause it will fetch only data which is actually needed.
Also note that SingleOrDefault
can return null, so without null check you can get NullReferenceException
.
Source: stackoverflow.com
Related Articles
- LINQ Source Code Available
- creating Linq to sqlite dbml from DbLinq source code
- source code for LINQ 101 samples
- c# Linq or code to extract groups from a single list of source data
- Convert string[] to int[] in one line of code using LINQ
- Code equivalent to the 'let' keyword in chained LINQ extension method calls
- Linq code to select one item
- How are people unit testing code that uses Linq to SQL
- Check if XML-node has attribute with Linq C#?
- Linq select object from list depending on objects attribute
- LINQ query to perform a projection, skipping or wrapping exceptions where source throws on IEnumerable.GetNext()
- Find an XElement with a certain attribute name and value with LINQ
- Syntax to execute code block inside Linq query?
- How to get attribute value using LINQ to XML?
- Linq to XML selecting a node bases on a attribute value
- Enumerable.Empty<T>().AsQueryable(); This method supports the LINQ to Entities infrastructure and is not intended to be used directly from your code
- LINQ to SQL entity column name attribute ignored with guid primary key
- Best open source LINQ provider
- Is there a good source that gives an overview of linq optimizations?
- Does this LINQ code perform multiple lookups on the original data?
- How to query xsi:type from an attribute using Linq to XML?
- How to understand the following C# linq code of implementing the algorithm to return all combinations of k elements from n
- LINQ WHERE method alters source collection
- Linq to Xml: selecting elements if an attribute value equals a node value in an IEnumerable<XElement>
- NHibernate linq - Use lambda expression in place of formula attribute on mapping
- Where can I view LINQ source code?
- Suggestions for designing complex LINQ code
- Is there any way to create a LINQ query as a variable without having the data source (yet)?
- What is DBML storage attribute in LINQ to SQL?
- Left outer join using LINQ -- understanding the code
- dynamically filtering a List using Reflection in LINQ
- Optionally loading/selecting a column in linq
- N-way intersection of sorted enumerables
- linq condition in select statement
- C# Lambda Method syntax to obtain attribute values that match pattern in LINQ to XML
- LINQ versus yield
- How to get top 4 result from a list using linq c#
- Different way of using LINQ in joining a single table
- Linq - Query on 2 Lists Optimization
- Exception when converting local realm to synced realm in Xamarin.iOS
- If all my sql server database access is done thru stored procedures
- WPF MVVM Validation using data annotation
- Sorting a collection containing strings and/or numbers
- Accessing child value of JSON in C#
- Building a linq expression with only field names
- How to compare two c# lists data equal using linq
- linq AncestorsAndSelf with null argument
- Linq query to join against list in a struct
- Linq query from list containing check for null condition
- Is it possible that filter IIS worker processes with more criteria?