Basic Queries

Learn how to load entities from the database using Language Integrate Query (LINQ).

Tip

You can view this article's sample on GitHub.

101 LINQ samples

This page shows a few examples to achieve common tasks with Entity Framework Core. For an extensive set of samples showing what is possible with LINQ, see 101 LINQ Samples.

Loading all data

using (var context = new BloggingContext())
{
    var blogs = context.Blogs.ToList();
}

Loading a single entity

using (var context = new BloggingContext())
{
    var blog = context.Blogs
        .Single(b => b.BlogId == 1);
}

Filtering

using (var context = new BloggingContext())
{
    var blogs = context.Blogs
        .Where(b => b.Url.Contains("dotnet"))
        .ToList();
}