linq to entities vs linq to objects – are they the same?

That is definitely not the case. LINQ-to-Objects is a set of extension methods on IEnumerable<T> that allow you to perform in-memory query operations on arbitrary sequences of objects. The methods accept simple delegates when necessary. LINQ-to-Entities is a LINQ provider that has a set of extension methods on IQueryable<T>. The methods build up an expression … Read more

Code equivalent to the ‘let’ keyword in chained LINQ extension method calls

Let doesn’t have its own operation; it piggy-backs off of Select. You can see this if you use “reflector” to pull apart an existing dll. it will be something like: var result = names .Select(animalName => new { nameLength = animalName.Length, animalName}) .Where(x=>x.nameLength > 3) .OrderBy(x=>x.nameLength) .Select(x=>x.animalName);

C# Linq where clause as a variable

You need to assembly an Expression<Func<T, bool>> and pass it to the Where() extension method: Expression<Func<T, bool>> whereClause = a => a.zip == 23456; var x = frSomeList.Where(whereClause); EDIT: If you’re using LINQ to Objects, remove the word Expression to create an ordinary delegate.

LINQ identity function

Unless I misunderstand the question, the following seems to work fine for me in C# 4: public static class Defines { public static T Identity<T>(T pValue) { return pValue; } … You can then do the following in your example: var result = enumerableOfEnumerables .SelectMany(Defines.Identity); As well as use Defines.Identity anywhere you would use a … Read more

Linq to Objects – return pairs of numbers from list of numbers

None of the default linq methods can do this lazily and with a single scan. Zipping the sequence with itself does 2 scans and grouping is not entirely lazy. Your best bet is to implement it directly: public static IEnumerable<T[]> Partition<T>(this IEnumerable<T> sequence, int partitionSize) { Contract.Requires(sequence != null) Contract.Requires(partitionSize > 0) var buffer = … Read more

Find() vs. Where().FirstOrDefault()

Where is the Find method on IEnumerable<T>? (Rhetorical question.) The Where and FirstOrDefault methods are applicable against multiple kinds of sequences, including List<T>, T[], Collection<T>, etc. Any sequence that implements IEnumerable<T> can use these methods. Find is available only for the List<T>. Methods that are generally more applicable, are then more reusable and have a … Read more

tech