score:15
Try to understand what's going on under the hood:
- How query expressions are translated by the compiler
- How LINQ to Objects streams its data, and how it defers execution
- How queries execute remotely via IQueryable and expression trees
It's also worth becoming comfortable with both query expressions, e.g.
var query = from person in people
where person.IsAdult
select person.Name;
and "dot notation":
var query = people.Where(person => person.IsAdult)
.Select(person => person.Name);
Knowing both will let you choose the most readable form for any particular query.
score:2
The best advice I could offer someone just starting with LINQ
is get LINQPad
. It is an invaluable tool and will speed up your learning process significantly. And it comes with lots and lots of samples that demonstrate, and let you work with, all the LINQ
operators.
score:2
You do it in LINQ like you would do in "normal" C#.
In your sample you used string.IsNullOrEmpty(), so you don't differentiate between null and "". If that's the case you could write sth. like the following:
if ((lastName ?? "") == (i.LastName ?? ""))
{
// equal
}
You can integrate that logic into your LINQ query as follows:
var peoples = from i in individuals
where (lastName ?? "") == (i.LastName ?? "")
select i;
score:5
101 LinQ Samples you can start with samples from MSDN
score:10
The result of a query expression is a query object, not the results of the query. If you want the results, you can ask the query object to start proffering up results. That is, when you say:
var names = from c in customers where c.City == "London" select c.Name;
then names is a query object that represents "get me the names of all the customers in London". It is not a sequence in memory of all the names of customers who live in London; the results of the query are computed on-demand. It is not until you say:
foreach(var name in names) ...
that the actual results are computed.
This means that if you ask the same query object for its results twice, the answer might be different. The customers list might have been changed between the first time you ask and the second time you ask. Because queries defer getting their results, you always get fresh results. But you sometimes do the same work twice.
Source: stackoverflow.com
Related Query
- Handling NULL Parameters in LINQ Queries
- Handling null results with the LINQ Average() method
- Automatically checking for NULL relationships with LINQ queries
- Handling LINQ "Count" queries as IDocumentQuery
- Linq to SQL - Ignore search parameters that are null or zero
- LINQ Source Code Available
- Linq to DataSet - Handling Null Values
- Handling large SQL queries with LINQ
- Exception handling in Linq queries
- Linq Query Handling Null Values
- creating Linq to sqlite dbml from DbLinq source code
- Does LINQ convert code to SQL queries
- Checking if an entity is null after linq queries
- LINQ String comparison with NULL handling
- CRM 2011 Custom Workflow Linq Queries providing null values when they are not null
- Handling null in Linq
- Handling null values inside a WHERE with ANY Condition in linq
- short circuting linq queries thowing null error
- linq null refactoring code
- Linq with null parameters not working
- Convert string to decimal within LINQ Average function while handling possible null values
- Passing null parameters into LINQ where clause
- Null reference exception in my LINQ to XML code
- How to handle nulls in this LINQ Code using a possible null List?
- source code for LINQ 101 samples
- Linq query null check in data source
- handling a null in linq to sql query
- Include null cells in Linq query from DB in C# code
- handling exceptions with linq queries
- Simplify the following code to a one-liner using Linq queries
More Query from same tag
- Are those 2 linq equivalent?
- error when converting linq lambda query to list
- Selecting a list of available numbers between a range, joining a reserved range table
- GroupJoin and Include
- Convert Session Object to IOrderedQueryable<T>
- IQueryable<T> gives different result than a List<T>
- Applying where clause to childcollection in LightSwitch query
- converting a c# linq statement into vb.net
- Linq's Aggregate Function, How to make a CSV String
- Does .Where(x=> x.listFoos.Count() > 1) count all sub element?
- Merging 2 dictionaries having duplicate keys with linq
- C# FileInfo - additional conditions in this LINQ query
- How do I set up a nested repetition?
- How to sort where an object is added to based on it's attribute
- Using LINQ to select distinct values between two tables
- Perform Join in linq
- Linq join that accepts null values
- Trying to close DataReader
- How to create new DataTable left-joining two in-memory Datatables (no data connection involved)?
- Why does this LINQ query compile?
- LINQ to Entities create dynamic field
- Looping through multiple collection of arrays
- Not able to return JsonResult
- LINQ GroupBy, whilst keeping all object fields
- LINQ Returning Empty Collection Where ForEach Finds A Value
- Selecting null in a select select clause in EF5
- Select * From tab1, tb2, tb3, etc in LINQ
- How to convert a LINQ query from query syntax to query method
- C# Linq how to compare two strings and report the first different char which is itself different from '?' wildcard
- Very Basic LINQ to SQL Question