efcore icon indicating copy to clipboard operation
efcore copied to clipboard

Include after select not load navigation property

Open MohammadAkbari opened this issue 9 years ago • 1 comments

I use entity framework core 1.1. I have a query like below, and I expect to users who have UserProfile by using Include, load UserProfile. but this query always return UserProfile null .

Query:

var user = dbContext.UserMappers
	.Where(e => e.OldUserId == id)
	.Select(e => e.User)
	.Include(e=>e.UserProfile)
	.FirstOrDefault();

Models:

public class UserMapper
{
    [Key, ForeignKey(nameof(User))]
    public string UserId { get; set; }
    public User User { get; set; }
    public int OldUserId { get; set; }
}

public class User : IdentityUser
{
    public bool Suspended { get; set; }
    public string Nickname { get; set; }
    public virtual UserProfile UserProfile { get; set; }
}

public class UserProfile : ICommonDate
{
    [Key, ForeignKey(nameof(User))]
    public string UserId { get; set; }
    public string Name { get; set; }
    public string Family { get; set; }
    public string Telephone { get; set; }
}

MohammadAkbari avatar Jan 18 '17 06:01 MohammadAkbari

dupe of #6451

maumar avatar May 01 '17 21:05 maumar