Web api c# relationship between tables

Asked

Viewed 208 times

0

I’m trying to make the relationship between two classes "Tables".

I am mounting an API for MVC5 EF6 in Visual Studio however I need information from one class to appear in the other.

public class ASSOCIADO
{

    public string ID_EMPRESA { get; set; }

    *public ICollection<EMPRESA> NM_FANTASIA_EMPRESA { get; set; }
    [Key]
    public string ID_ASSOCIADO { get; set; }
    public string NM_ASSOCIADO { get; set; }
    public string NR_CPF { get; set; }
    public string DS_EMAIL { get; set; }
    public DateTime? DT_NASCIMENTO { get; set; }
    public DateTime? DT_INATIVACAO { get; set; }

    *public virtual EMPRESA NM_FANSTASIA_EMPRESA { get; set; }

}

In this code above, I have the member information and I have CD_EMPRESA (KEY in Company Class), the codes with * were some attempts found on the internet to bring these values.

In another Class I have this code:

public class EMPRESA
    {
            [Key]
            public string ID_EMPRESA { get; set; }
            public string NM_FANTASIA_EMPRESA { get; set; }

    }

I need to present the NM_FANTASIA_EMPRESA in the ASSOCIATED class, so that according to its ID_EMPRESA.

  • an associate has 1 or several companies ? if 1, uses the code below, if not, the code above. Can remove public string ID_EMPRESA { get; set; } of the associate also

  • 1

    @Rovannlinhalis he has only 1 company.

  • 1

    @Rovannlinhalis I made the change and searched the value I wanted, thank you!

No answers

Browser other questions tagged

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