I'm using code first EF5 and I have an object which has a collection defined as virtual
(lazy loaded). This returns data when called. However I want it to be eager loaded. I've removed virtual
from the property signature but now it always returns null
data. EF doesn't even run the query, can anyone help?
Edit: I know about .include()
I'd just prefer to use the non-virtual property method of doing it.
Objects
User
([Key]
Id is on Resource object which is the Parent of person class):
namespace Entities
{
[Table("Users")]
public class User : Person
{
[Required]
public ICollection<Role> Roles { get; set; }
}
}
Role:
namespace Entities
{
public class Role
{
[Key]
public string Id { get; set; }
public virtual ICollection<User> Users { get; set; }
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…