I have several entities that I want to give the possibility to store files. Like for a given customer, storing a copy of it's identity card or for a product, storing it's import documents and also quality certificates.
I don't want those files to be stored in the same entities rows and I've created a separate table for attachments. Decoupling it also gives the opportunity to later decide if I want to directly store the file, the storage location or some CMS access token.
So how I can make in EF for having such relationship between this attachments table and all the other tables that may have that functionalty?
An schema sample:
public class Customer
{
[Key]
public int Id { get; set; }
public string Name { get; set; }
}
public class Product
{
[Key]
public int Id { get; set; }
public string Name { get; set; }
}
public class Attachment
{
[Key]
public int Id { get; set; }
//Relation property
public int ParentId { get; set; }
public string Name { get; set; }
public byte[] Content { get; set; }
}