How to Create a Table N: N Where One of the Keys Does Not Belong to a Table of the Same Database

1

Context:

The application has a module for logging of calls and we use another application to deal with the record of incidents, both are in different databases.

Each care may be related to one or more incidents and an incident may be related to one or more care. I'm using EntityFramework in an application ASP. Net MVC .

Request

I need to associate these requests with the incidents, I do not see a way to do this because they are from different databases.

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 (n:n) ? relationship

    
asked by anonymous 30.12.2017 / 16:38

1 answer

0

As you do not have one side of your template you will have to treat it as 1 / N, and map the id of the other table. I do not see any other way to do this unless you have the template completely.

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

When your data persist, tell the PK of your table belonging to the other bank.

    
02.01.2018 / 12:59