DEV Community

loading...
Cover image for LINQ Queries | Dev [Over]simplified

LINQ Queries | Dev [Over]simplified

Kasey Wahl
developer | tech blogger | language lover
・3 min read

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

Glootie

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!

migration

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
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

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

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

Data from M'lady

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

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.

Introduction to LINQ Queries
LINQ Tutorial

Discussion (0)