4
Good Afternoon!
I have the "Service Order" and "Attachment" tables. In my "Service Order" table, I want to be able to attach the scanned service order and be able to attach pictures of the equipment.
Work order
[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 for the Annex
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 easily. I know it would be better to put the relationship in the table "Attachment", but I can’t do it in a good way. I tried the following:
public int? FotosDoEquipamento_Id { get; set; }
[ForeignKey("FotosDoEquipamento_Id")]
public virtual OrdemDeServico FotosDoEquipamento { get; set; }
Only that still creating "Ordemdeservico_id", must be the relationship on account of the orderSampled, but the foreign key is in another table, and I thought it would not give problem.
The point is that I don’t know how to add the photos. I didn’t want to create another table just for this, since this one already has what I need.
The table design created by the system:
maybe it’s me, but I don’t quite understand.
OrdemDeServico
has aAnexo
,Anexo
has aOrdemDeServico
. 1:N mapping should work as you did. What is not working?– RSinohara
Now I saw that there are two relations between the entities. That must be what is causing the problem. Maybe someone can, but I could only find out by running the code. If you can, put here the database schema generated by your code.
– RSinohara
That’s right. Ordemdeservico in an Orderly property of type Attachment, and other Photosdoequipment of type attachment as well. This got a little confusing on how to do relationship.
– Euripedes Barsanulfo de Araujo
I want to use the same table "Attachment" both to save the Ordemescaneada(One unit), and Photosescaneadas(0 or x units).
– Euripedes Barsanulfo de Araujo