I'm a bit of an EF newb and I'm using .net core and I just can't seem to load the related entities of an entity unless I do a full-fledged "from..in..join" linq statement.
My entities have Guid primary keys and I'm using SQL Server as a DB.
Let's look at one entity that I'm having trouble with.
[Table("User")]
public class User : AuditableEntity
{
public Group CurrentlySelectedGroup { get; set; }
}
[Table("Group")]
public class Group : AuditableEntity
{
public string Name { get; set; }
}
A user can pick one group as their "selected" group. I ran the migration statement and sure enough it created exactly what I wanted on the DB - a brand new column called CurrentlySelectedGroupId that was a FK to the Group table's PK column.
So this looks great.
I then ran some code that added a valid Guid for a valid group into the table.
Now when I execute this line of code:
var user = _dbContext.Users.Where(u => u.Id == userId).FirstOrDefault();
It returns my user perfectly, but all the related entities are null. I've even tried things like .Include(), including 'virtual', but no luck.
Any idea what I'm doing wrong?
Thanks!