How best to represent a FK in the field

Asked

Viewed 44 times

0

I have for example two entities in my BD. Type_user and User. User receives a Typo_user FK from the Idtipousuario field. In my Domain(C#) I would have:

TipoUsuario
public int IDTipoUsuario { get; set; }
public string NmTipoUsuario { get; set; }

And in my user class I would have

Usuario
public int IdUsuario { get; set; }
public string NmUsuario { get; set; }
public virtual ICollection<int> IdTipoUsuario { get; set; }

I need also in the table of Tipousuario to do this

public virtual Usuario usuario { get; set; }

Just that is either enough to represent a foreign key (FK) in my class or I need to do more?

  • A user will have multiple types or a type will have multiple users? It seems that has a concept error.

  • User will have several types, so I made a user Icollection

  • But one type (probably) may have more than one user.

  • @LINQ, yes, that’s right

  • 1

    then on TipoUsuario you also have to have a Icollection]

  • @Rovannlinhalis, I just won’t need Icollection<> at one of the tips, when I have a 1:N, right? And where does the associative table enter? How do I represent it in my domain?

Show 1 more comment
No answers

Browser other questions tagged

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