Skip to content

About lazy loading issues in EF Core 3.0 #18358

@JohnHe404

Description

@JohnHe404
ApplicationDbContext _context;
Cdkeys = this._context.Set<CdKey>();
KeyValues = this._context.Set<KeyValue>();
var keys = Cdkeys.Where(k => k.BuildType == (int)BuildKeyType.Test);
 foreach(var key in keys)
 {
var values = KeyValues.Where(v => v.KeyId == key.Id).ToList();//InvalidOperationException: 
//There is already an open DataReader associated with this Command which must be closed first.
}
var keys = Cdkeys.Where(k => k.BuildType == (int)BuildKeyType.Test).ToList();//Because the loading is done
 foreach(var key in keys)
 {
var values = KeyValues.Where(v => v.KeyId == key.Id).ToList();//So,No error
}
  1. I don't think this lazy loading is bad, instead I think it's very cool.
  2. I hope the official can have some documentation about this, or help other through my example.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions