Sobes.tech
Junior — Middle

What types of relationships between fields in tables are you familiar with?

sobes.tech AI

Answer from AI

The main types of relationships between fields in tables that I am familiar with:

  • One-to-One: Each record in table A is related to exactly one record in table B.
  • One-to-Many: One record in table A is related to multiple records in table B.
  • Many-to-Many: Records in table A can be related to multiple records in table B and vice versa. Usually implemented through an intermediate table.

Example of a one-to-many relationship in C# using Entity Framework:

public class Author {
    public int Id { get; set; }
    public string Name { get; set; }
    public ICollection<Book> Books { get; set; }
}

public class Book {
    public int Id { get; set; }
    public string Title { get; set; }
    public int AuthorId { get; set; }
    public Author Author { get; set; }
}