Permalink
Fetching contributors…
Cannot retrieve contributors at this time
51 lines (40 sloc) 1.32 KB
title author ms.date ms.assetid uid
Basic Queries - EF Core
rowanmiller
10/27/2016
ab6e35f1-397f-41c0-9ef4-85aec5466377
core/querying/basic

Basic Queries

Learn how to load entities from the database using Language Integrated 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();
}