0

I have a class which looks like below:

    public string Id { get; set; } = default!;
    public double? Name { get; set; } = default!;
    public string? FamilyName { get; set; } = default!;
    public List<Addresses> ClientAddress { get; set; } = default!;

here is my Adresses class :

    public string Id { get; set; } = default!;

    public string Address { get; set; } = default!;

I have found this approach on stack overflow, we use when we need to store a list in database with one to many relationship,but what i dont get is how these two tables can be connected by using the class name in the first table as a list?i dont understand how you insert into Address table for example ,anyone can help me by explaining how this works?

moris62
  • 983
  • 1
  • 14
  • 41
  • Does this answer your question? [How to store list in SQL Server from ASP.NET Core?](https://stackoverflow.com/questions/69398019/how-to-store-list-in-sql-server-from-asp-net-core) – OneCricketeer Sep 30 '21 at 21:45

1 Answers1

0

The mentioned approach most probably uses Entity Framework Core. This is an object relational mapper. It can create a database shema out of C# objects. It further also encapsulates all the reads and writes to the database so that you conveniently have only to deal with C# objects stored in memory. It works with many different databases.

In your example it would treat the Address Propertiy in the Address class as a Foreign Key. This Foreign Key maps to the Id of the Person (I assume of the properties) that the Address belongs to. Because a person can have many Addresses EF Core establishes a one to many relationship between persons and addresses.

Link to EF Core documentation.