Я использую EF Core 2.1 и пытаюсь получить профиль из аутентификации, но каждый раз, когда я его получаю, я обнаруживаю, что он нулевой, и я не знаю, в чем проблема.
А для аутентификации я могу получить профили.
Объекты:
[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);
}
Как правильно использовать отношения