sandersade / common-linq-mistakes Goto Github PK
View Code? Open in Web Editor NEWList of common LINQ mistakes
License: Mozilla Public License 2.0
List of common LINQ mistakes
License: Mozilla Public License 2.0
If I know that provider knows how to combine multiple Where-s then multiple Where-s improve readability quite a lot.
Long non readable && || combination can be really pain to read.
Hi,
Nice write-up! However, few comments:
Common LINQ mistakes
Reads more like Common LINQ to Entitles mistakes. Most explanations dive into resulting SQL issues. But also there are LINQ to Objects, to XML, other IQueryable implementations, to Cosmos DB, etc. which or might not have these issues, or might have different ones.
Single() methods go over all elements of the set
Single(predicate)
Single()
on all platforms basically will make just 2 iterations instead of 1. If logically or semantically there should be only a single element, it's fine to use it because the penalty is insignificant.I am not sure why people just select the items
IEnumerable
instead of a concrete class, probably. There is special method ToEnumerable()
but this is still a common mistake.I don't see this one listed.
Correct solution is to use Contains, or to use SqlBulkCopy and load your IEnumerable into a temp table and join on that.
Hey,
First let me say, your article and explanations are great.
As a developer working with legacy code and old conventions/standards, I come across these mistakes daily.
I want to suggest some tips on finding these mistakes, using regular expressions:
use: \.Single(OrDefault)?\(.*\)
use: \.First(OrDefault)?\(.*\)
use: \.Count\(\)
use: \.Count\(.*\)
or in this case if.*\(.*\.Count\(.*\)\)
might help.
use: \.Where\(.*\)\.First(OrDefault)?\(.*\)
use: \.Where\(.*\)\.Where\(.*\)
use: \.OrderBy\(.*\)\.OrderBy\(.*\)
use: \.Select\((\w)\s*=>\s*\1\)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.