Я использую EF Core с первым кодом, и у меня есть модель Company
public class Company
{
public Guid Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public DateTime FoundationDate { get; set; }
public string Address { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public string Logo { get; set; }
public ICollection<Contact> Contacts { get; set; }
}
и модель Контакт.
public class Contact
{
public Guid Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public Guid CompanyId { get; set; }
public Company Company { get; set; }
public ICollection<Resource> Resources { get; set; }
}
И я пытаюсь установить отношения между ними через FluentAPI в методе OnModelCreating через modelBuilder.
modelBuilder.Entity<Company>()
.HasMany<Contact>(s => s.Contacts)
.WithOne(g => g.Company)
.HasForeignKey(s => s.CompanyId);
modelBuilder.Entity<Contact>()
.HasOne<Company>(s => s.Company)
.WithMany(g => g.Contacts)
.HasForeignKey(s => s.CompanyId);
Какой из них правильный и есть ли разница?