Giter VIP home page Giter VIP logo

common-linq-mistakes's People

Contributors

sandersade avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

common-linq-mistakes's Issues

.Where().Where()

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.

Few comments

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

  • Goes or will go :)
  • Concerns only 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

  • Usually a left over after refactoring, indeed.
  • Or to return IEnumerable instead of a concrete class, probably. There is special method ToEnumerable() but this is still a common mistake.

Suggestion: Regular Expressions to find mistakes

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:

.Single() and .SingleOrDefault()

use: \.Single(OrDefault)?\(.*\)

.First() and .FirstOrDefault()

use: \.First(OrDefault)?\(.*\)

Empty .Count()

use: \.Count\(\)

Other occurences of .Count()

use: \.Count\(.*\)
or in this case if.*\(.*\.Count\(.*\)\) might help.

.Where().First() and .Where().FirstOrDefault()

use: \.Where\(.*\)\.First(OrDefault)?\(.*\)

.Where().Where()

use: \.Where\(.*\)\.Where\(.*\)

.OrderBy().OrderBy()

use: \.OrderBy\(.*\)\.OrderBy\(.*\)

.Select(x => x)

use: \.Select\((\w)\s*=>\s*\1\)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.