I want to create a Projectofuncionario class...
There is no need to create a class like Projectofuncionario to express these relationships. This usually occurs when creating the database tables, then you create a table to express the relationship, but the modeling of your objects will not look exactly like you model your database.
You can work only the classes Funcionario
(or FuncionarioModel
as you called it) and Project itself.
...would like to instantiate the primary key of the two in this class. How can I do?
In fact, you do not have a primary key instance, because the primary key is related to the field(s) of the object(s). As we know, you create instances of objects (such as Functionary, Project, etc....).
You can create the class instance Projeto
, create the instance(s) (s) of the project employee(s) and add each object Funcionario
on the list. When you save the Project in the database, the framework you use (Entity Framework, Nhibernate, etc...) will make the association (saving the information in the tables of Projeto
, Funcionario
and ProjetoFuncionario
and even generating the Ids automatically) for you.
//Instancia os objetos para exemplificar
Projeto projeto_novo = new Projeto() { nome_Projeto = "Projeto 1", lista_funcionarios = new List<Funcionario>() };
Funcionario funcionario_novo1 = new Funcionario() { nom_funcionario = "Funcionário 1" };
Funcionario funcionario_novo2 = new Funcionario() { nom_funcionario = "Funcionário 2" };
//Adiciona os funcionários na lista
projeto_novo.lista_Funcionarios.Add(funcionario_novo1);
projeto_novo.lista_Funcionarios.Add(funcionario_novo2);
One point of attention I noticed here is about the property names, because where you are using "listProject" I used "list_functionalities" in the example, just because I believe it is clearer (just suggestion).
If I haven’t answered your question yet, please enter a comment so I can help :-)
What do you mean by instantiating the primary keys? You want to make a reference of this new class to Employee and Project I suppose... for that just create a class like this:
public class ProjetoFuncionarioModel { public ProjetoModel Projeto { get; set; } public FuncionarioModel Funcionario { get; set; } }
.– Miguel Angelo
i want to create a PROJECTOFUNCIONARIO class in this class i want to instantiate the working key and the design key
– chewie