LINQ Queries | Dev [Over]simplified
Tags: csharp, beginners, codenewbie, entityframework
Published: 2021-06-23 17:22:13

So you're eating at the dinner table when this alien come's up to you like:

![Glootie](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](http://www.dear-coder.com/KaseysPosts/SEOFriendly/c-sharp-classes-objects-and-class-members-explained-by-dan-harmons-community) 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!

![migration](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.

![star-crossed lovers](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9n5rz911qeactbtpnflb.jpg)
If only there was something...someone who could take a request in C# and translate it into usable SQL code that the database could understand!

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:

![LINQ](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.

![LINQ Query](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().

![Data from M'lady](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.

![LINQ saves the data](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:

{% youtube C_6raHHDLEA %}

---
### Want to learn more about LINQ?

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.

[Introduction to LINQ Queries](https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/linq/introduction-to-linq-queries)
[LINQ Tutorial](https://www.tutorialsteacher.com/linq/linq-query-syntax)