Now I've realized that it is something hard to do for me.
Given:
EF Core 8
// мodels are simplified to highlight the essence
public class Notification
{
public Guid Id { get; set; }
public EmailAddress From { get; set; }
public ICollection<EmailAddress> To { get; set; }
public ICollection<EmailAddress> Cc { get; set; }
public ICollection<EmailAddress> Bcc { get; set; }
public string Subject { get; set; }
public string Body { get; set; }
}
public class EmailAddress
{
public string DisplayName { get; set; }
public string Address { get; set; }
}
Need to get some configuration that the all email addressed will end up in the same table with some discriminator column maybe. Like
notification table
| id | from | subject | body |
|---|
emailaddresses table
| id | notification_id | to | cc | bcc | discriminator |
|---|
or more preferable
| id | notification_id | address | discriminator |
|---|
You can use the table-per-hierarchy with a discriminator feature to do this.
Extend
EmailAddressto have a type per collection:Modify
Notificationuse the new types:Update the model configuration for
EmailAddressto register the new types and desired discriminators: