17
LINQ Queries | Dev [Over]simplified
So you're eating at the dinner table when this alien come's up to you like:
![](https://res.cloudinary.com/practicaldev/image/fetch/s--UxpjZsF0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2gu44x0age81bbu2yivv.png)
And you're like, "Sure."
So you decide you're going to code up a blog in C# because you need a place to store all of your ideas.
So you code up classes in the shape of Posts, Blogs, and Comments--everything you need for a basic blog.
You find some cute HTML blog template, slap it into your Solution, and you're ready to publish.
And then it occurs to you:
You don't have anywhere to store your data--the strings and ints and DateTimes that, for now, you're storing in that big ol' head of yours.
You're alien friend's like, "Hey, I've got an idea. Why don't you store all that in a database?"
You're like, "That's pretty chill."
So you download a bunch of NuGet packages, wire your database to your solution, set your first data migration, and you're set!
![](https://res.cloudinary.com/practicaldev/image/fetch/s--k2sKbNnH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2fye8e14efe0qgmq3v2i.png)
Or so you thought.
You've actually just encountered another roadblock.
Even though you're wired to a database that stores all of the data tables you need, you don't speak SQL, the language that databases understand.
Your application consists of two star-crossed lovers who's love letters are lost at sea.
![](https://res.cloudinary.com/practicaldev/image/fetch/s--_mnAq2ho--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9n5rz911qeactbtpnflb.jpg)
The dark hour is upon you. You've lost sleep. It shows in the sagging, fleshy bags under your eyes.
It seems all hope is lost. You're about to raise the white flag of defeat.
That is...
Until LINQ, our hero arrives:
![](https://res.cloudinary.com/practicaldev/image/fetch/s--E-qmLxRo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j1ljv73h19iwfctldaue.png)
LINQ, or Language Integrated Query, takes your C# request and translates it into something that your SQL-speaking database knows what to do with.
![](https://res.cloudinary.com/practicaldev/image/fetch/s--oIGuAe9g--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ju6hhbr0gih1m5wq615v.png)
Wanna store some blog data? Use LINQ to tell that dataBaby where to put it and .SaveChangesAsync().
![](https://res.cloudinary.com/practicaldev/image/fetch/s--UMJvo8v---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/38hpinw1wosh6ffk1pdx.png)
Wanna spin up a Post to display in your application? Tell LINQ to hit the Post table. Don't forget to .Include() all of the comments.
![](https://res.cloudinary.com/practicaldev/image/fetch/s--nuylF289--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gbn2wa67rj4bppsq17oh.png)
In short, LINQ is our hero that allows us C# devs to query a database (among other things) and make that data sing, baby:
I hope you enjoyed this entry in my Dev [Over]Simplified series, dear Coder. If you want a more technical explanation on LINQ, check out the resources below.
17