Caution

This documentation is for EF Core. For EF6.x and earlier release see http://msdn.com/data/ef.

Basic Query

Entity Framework Core uses Language Integrate Query (LINQ) to query data from the database. LINQ allows you to use C# (or your .NET language of choice) to write strongly typed queries based on your derived context and entity classes.

In this article:

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

1
2
3
4
using (var context = new BloggingContext())
{
    var blogs = context.Blogs.ToList();
}

Loading a single entity

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

Filtering

1
2
3
4
5
6
using (var context = new BloggingContext())
{
    var blogs = context.Blogs
        .Where(b => b.Url.Contains("dotnet"))
        .ToList();
}