Skip to content

Query: LoadAsync does not work #6122

@ajcvickers

Description

@ajcvickers

No entities end up being tracked.
Repro:

public class BloggingContext : DbContext
{
    public DbSet<Blog> Blogs { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        => optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=LoadAsyncTest;Trusted_Connection=True;");
}

public class Blog
{
    public int Id { get; set; }
    public string Title { get; set; }
}

public class Program
{
    public static void Main()
    {
        Task.Run(async () =>
        {
            await MainAsync();
        }).Wait();
    }

    public static async Task MainAsync()
    {
        using (var context = new BloggingContext())
        {
            context.Database.EnsureDeleted();
            context.Database.EnsureCreated();

            context.AddRange(new Blog(), new Blog());
            await context.SaveChangesAsync();
        }

        using (var context = new BloggingContext())
        {
            await context.Blogs.LoadAsync();

            Console.WriteLine(context.ChangeTracker.Entries().Count());
        }
    }
}

Output is 0; expected output is 2.
When run with Load instead of LoadAsync, output is 2 as expected.

Note that there are currently zero tests for LoadAsync.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions