Я не совсем уверен, как обрабатывать отношения в ядре платформы сущностей с помощью провайдера Firebird. Я получил таблицу «Пользователи» и «Сотрудники». Они получили отношение один-к-одному, используя столбец «имя пользователя». Я попробовал несколько уроков, но не смог заставить его работать. Моя цель - получить доступ к полю «Сотрудник», вызвав user.Employee. Но в большинстве случаев оно просто пустое или выдает ошибки при использовании LazyLoad. Мне кажется, что я не понимаю правильного подхода к этому.
Кстати, я уже спросил в firebird. net провайдерская группа Google
User.cs:
public class User {
public string Username { get; set; } // Primary key in db
public string Passwd { get; set; }
/* ... */
public virtual Employee Employee { get; set; }
}
Employee.cs:
public class Employee {
public int Id { get; set; }
public int EmployeeNumber { get; set; }
/* ... */
[ForeignKey("User")]
public string Username { get; set; } // Foreign key in db
public virtual User User { get; set; }
}
Context.cs
protected override void OnModelCreating(ModelBuilder modelBuilder) {
configureTable(modelBuilder.Entity<Employee>());
configureTable(modelBuilder.Entity<User>());
/* ... */
}
private static void configureTable(EntityTypeBuilder<Employee> tc) {
tc.HasKey(x => new { x.Id });
tc.Property(x => x.Id).HasColumnName("EMPLOYEE_ID");
tc.Property(x => x.Username).HasColumnName("USERNAME");
/* ... */
//tc.HasOne(x => x.User).WithOne(u => u.Employee).HasForeignKey<User>(n => n.Username); // Is this the correct configuration?
tc.ToTable("EMPLOYEES");
}
private static void configureTable(EntityTypeBuilder<User> tc) {
tc.HasKey(x => new { x.Username });
/* ... */
tc.Property(x => x.Username).HasColumnName("USERNAME");
tc.Property(x => x.Passwd).HasColumnName("PASSWD");
//tc.HasOne(x => x.Employee).WithOne(u => u.User).HasForeignKey<Employee>(n => n.Username); // Do I have to do something similar here?
tc.ToTable("USERS");
}