OrderBy descending in Lambda expression?

As Brannon says, it’s OrderByDescending and ThenByDescending: var query = from person in people orderby person.Name descending, person.Age descending select person.Name; is equivalent to: var query = people.OrderByDescending(person => person.Name) .ThenByDescending(person => person.Age) .Select(person => person.Name);

Entity Framework: There is already an open DataReader associated with this Command

It is not about closing connection. EF manages connection correctly. My understanding of this problem is that there are multiple data retrieval commands executed on single connection (or single command with multiple selects) while next DataReader is executed before first one has completed the reading. The only way to avoid the exception is to allow … Read more

How to take the first N items from a generator or list? [duplicate]

Slicing a list top5 = array[:5] To slice a list, there’s a simple syntax: array[start:stop:step] You can omit any parameter. These are all valid: array[start:], array[:stop], array[::step] Slicing a generator import itertools top5 = itertools.islice(my_list, 5) # grab the first five elements You can’t slice a generator directly in Python. itertools.islice() will wrap an object … Read more

LINQ equivalent of foreach for IEnumerable

There is no ForEach extension for IEnumerable; only for List<T>. So you could do items.ToList().ForEach(i => i.DoStuff()); Alternatively, write your own ForEach extension method: public static void ForEach<T>(this IEnumerable<T> enumeration, Action<T> action) { foreach(T item in enumeration) { action(item); } }

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)