Q:

How to get table using relationships in Entity Framework

I am using EF Core 2.1 and i'm trying to get Profile from Authentication but every time i get it i found it null and i don't now where is the problem.
And for authentication i can get profiles.
Entities:
[Table("USER_AUTHENTICATION")]
public class Authentication
{
    public int ID { get; set; }
    //...some code
    [ForeignKey("ProfileID")]
    public Profile Profile { get; set; }
    public virtual int ProfileID { get; set; }

}

[Table("USER_PROFILE")]
public class Profile
{
    public Profile()
    {
        Authentication = new HashSet<Authentication>();
    }

    public int ID { get; set; }
    //... some code
    public virtual ICollection<Authentication> Authentication { get; set; }

}

DataContext
public DataContext(DbContextOptions<DataContext> options) : base(options) { }

public DbSet<Authentication> Authentications { get; set; }
public DbSet<Profile> Profiles { get; set; }

public Profile GetById(int currentUserId)
{
     var user = _context.Authentications.Find(currentUserId);
     Console.WriteLine(user.Profile); //<--- here is the probelm null//
     return _context.Profiles.Find(user.ProfileID);
}

How can i use relations with correct way

A:

You need use include for sub-entity and change Find to SingleOrDefault.
Add Include
var user = _context.Authentications.Include(p => p.Profile).SingleOrDefault(currentUserId);
return user.Profile;

