How to Create an N:N Table where one of the keys does not belong to a table of the same database

Asked

Viewed 44 times

1

Context:

The application has a module for record of calls and we use another application handle the incident record, both are in different database.

Each call can be related to one or more incidents and an incident may be related to one or more calls. I’m using EntityFramework in an application ASP. Net MVC.

Soliciting

I need to link these calls to the incidents, I don’t see a way to do that because they’re from a different database.

I thought about doing something like this, but I’m not sure about being a good solution:

[Table("AssociacaoAtendimentoIncidente")]
public class AssociacaoAtendimentoIncidente
{
    public int AtendimentoId { get; set; } //Pertence ao banco de dados atual.

    public int IncidenteId { get; set; } //Pertence a outro banco de dados.
}

How to create a table that represents this relation(n:n) ?

  • You have the contexts of the two banks mapped in your solution?

  • I don’t, because they belong to different solutions.

  • So I don’t quite understand what you want to do, so Atendimentoid and Incidenteid are just attributes without any integrity enhancement.

  • They are related, but not at the application level, but at the business level.

1 answer

0

As you do not have one side of your template you will have to treat as 1/N, and map the ID of the other table. I don’t see any other way to do that, unless you have the whole model.

[Table("AssociacaoAtendimentoIncidente")]
public class AssociacaoAtendimentoIncidente
{
    // FK
    public int AssociacaoAtendimentoIncidenteId { get; set; }
    // PK
    public int AtendimentoId { get; set; }
    // PK
    public int IncidenteId { get; set; } 
}

When persisting your data inform PK of your table belonging to the other database.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.