Entity Framework, Navigation Properties, and the Repository Pattern

Generic Repository vs Non-generic Repository Generic repository is not a pattern. Generic repository is just a wrapper. It can be useful for some special scenarios as a base class for specific repositories but in most cases it is just over used and over hyped nonsense. Navigation properties Repository itself should be used with aggregate root. … Read more

What actually happens when using async/await inside a LINQ statement?

I recommend that you not think of this as “using async within LINQ”. Keep in mind what’s in-between the two: delegates. Several LINQ operators take delegates, and async can be used to create an asynchronous delegate. So, when you have an asynchronous method BazAsync that returns a Task: Task BazAsync(TBar bar); then this code results … Read more

Except has similar effect to Distinct?

The documentation for the Except function states: Produces the set difference of two sequences by using the default equality comparer to compare values. The set difference of two sets is defined as the members of the first set that do not appear in the second set. The important word here is set, which is defined … Read more

Linq – What is the quickest way to find out deferred execution or not?

Generally methods that return a sequence use deferred execution: IEnumerable<X> —> Select —> IEnumerable<Y> and methods that return a single object doesn’t: IEnumerable<X> —> First —> Y So, methods like Where, Select, Take, Skip, GroupBy and OrderBy use deferred execution because they can, while methods like First, Single, ToList and ToArray don’t because they can’t. … Read more

LINQ: Add RowNumber Column

Use the method-syntax where Enumerable.Select has an overload with the index: var myResult = someTable.Select((r, i) => new { Row = r, Index = i }) .Where(x => x.Row.someCategory == someCategoryValue) .OrderByDescending(x => x.Row.createdDate); Note that this approach presumes that you want the original index of the row in the table and not in the … Read more