Two Foreign Keys of the Same Class C#

Asked

Viewed 19 times

-1

I am starting learning in EF Core and I am putting together a "little project" to follow the course. Okay, that’s enough to find the first difficulty. I need to create and link two classes where the Situation class needs to have two foreign key properties of the same relationship class as the User class. The same User needs to be linked to the property Inclusaousuarioid and Alteracaousuarioid

Classes

  • if you are using EF in the Situation class you should use it like this: public virtual Usuario UsuarioInclusao { get; set; } and public virtual Usuario UsuarioAlteracao { get; set; } and map the two when creating the model, in the method OnModelCreating

  • Solved, thank you very much!! What I don’t understand is that where I started the examples for the architecture, it was instructed to use: public Nameglass Nameglasse {get;set;} public int Nameserve{get;set;} For the first field (Inclusaousuarioid) worked, already when applying for the second (Alteracaousuarioid) the IDE presented error not allowing to recompile. This comment was just to illustrate my problem, the good thing is that you brought me the solution. Thank you.

  • the name can be whatever you want, for that has the mapping there in the OnModelCreating where you can tell what each Property does :)

No answers

Browser other questions tagged

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