LINQ Queries | Dev [Over]simplified

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

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!

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.

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, or Language Integrated Query, takes your C# request and translates it into something that your SQL-speaking database knows what to do with.

Wanna store some blog data? Use LINQ to tell that dataBaby where to put it and .SaveChangesAsync().

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.

In short, LINQ is our hero that allows us C# devs to query a database (among other things) and make that data sing, baby:

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.