Reputation: 1045
I have a model which i need create a table and database from it, but the problem is my class is nested:
public class PaymentModel
{
public string CreditorName { get; set; } = default!;
public CreditorAccounts CreditorAccount { get; set; } = default!;
public DebtorAccounts DebtorAccount { get; set; } = default!;
public InstructedAmounts InstructedAmount { get; set; } = default!;
public string RemittanceInformationUnstructured { get; set; } = default!;
public class CreditorAccounts
{
public string Iban { get; set; } = default!;
public string Currency { get; set; } = default!;
}
public class DebtorAccounts
{
public string Iban { get; set; } = default!;
public string Currency { get; set; } = default!;
}
public class InstructedAmounts
{
public string Currency { get; set; } = default!;
public string Amount { get; set; } = default!;
}
public class PaymentAccounts
{
public string Iban { get; set; } = default!;
public string Currency { get; set; } = default!;
}
public class PaymentAmounts
{
public string Currency { get; set; } = default!;
public string Amount { get; set; } = default!;
}
}
whats the best practice here?should create a table for each class?and join them?or there is a better way to create a single table ?
Upvotes: 1
Views: 76
Reputation: 414
i strongly suggest use entity framework if you have knowledge. You should create a table for each classes that provide easy control and makes it more developable on future if you need. You do not have to join them. Create your tables like;
CreditorName: Id(int), CreditorName.
CreditorAccount: Id(int), CreditorId(int), Iban, Currency
You can reach all data connected with creditorname by CreditorId.
Upvotes: 2