Good afternoon!
I have the tables "Order of Service" and "Attachment". In my "Service Order" table, I want to be able to attach the scanned service order and be able to attach photos of the equipment.
Order of service
[Table("OrdemDeServico")]
public class OrdemDeServico
{
public OrdemDeServico()
{
OrdemEscaneada = new Anexo();
FotosDoEquipamento = new List<Anexo>();
}
[Key]
public int Id { get; set; }
public int? OrdemEscaneada_Id { get; set; }
[Display(Name="Ordem de Serviço")]
[ForeignKey("OrdemEscaneada_Id")]
public virtual Anexo OrdemEscaneada { get; set; }
public virtual List<Anexo> FotosDoEquipamento { get; set; }
...
Now the Attachment
public class Anexo
{
[Key]
public int Id { get; set; }
[StringLength(80)]
public string Nome { get; set; }
public Byte[] Arquivo { get; set; }
}
I can add and remove the scanned order without problems. I know it would be better to put the relationship in the "Attachment" table, but I can not do it in a good way. I've tried the following:
public int? FotosDoEquipamento_Id { get; set; }
[ForeignKey("FotosDoEquipamento_Id")]
public virtual OrdemDeServico FotosDoEquipamento { get; set; }
The point is that I do not know how to add the photos. I did not want to create another table just for this, and this one already has what I need.
The design of the table created by the system: