1
The notation of the Entity Framework is "very polluted" if you take into account how I am used to defining the Domain classes, wanted to know if it is correct to have an EF model class to represent the database data and one to represent the domain class.
Example of RU model class:
User class
public class UsuarioDominio
{
public string Matricula { get; set; }
public string Nome { get; set; }
public string Login { get; set; }
public virtual List<Atividade> AtividadesResponsavel { get; set; }
}
Activity class
public class Atividade
{
public int ID { get; set; }
public string Titulo { get; set; }
public string Descricao { get; set; }
public DateTime DataInicio { get; set; }
public string ResponsavelID { get; set; }
public virtual UsuarioDominio Responsavel { get; set; }
public string Status { get; set; }
}
Class example used normally:
User class
public class UsuarioDominio
{
public string Matricula { get; set; }
public string Nome { get; set; }
public string Login { get; set; }
}
Activity class
public class Atividade
{
public int ID { get; set; }
public string Titulo { get; set; }
public string Descricao { get; set; }
public DateTime DataInicio { get; set; }
public UsuarioDominio Responsavel { get; set; }
public char Status { get; set; }
}
From what I understood from EF the class that will be the "model for the table" must have the same properties as the table as FK’s (Responsavelid), for example. Besides being necessary to add in the other class the virtual List since it has the relationship of 1 : N.
I’m still learning and maybe I’m talking nonsense, but from what I understand is more or less how it works (I even find it redundant to have the int Responsavelid and the virtual User Domain Responsavel).
The question is, do I use the Domain class as I’m used to, use only the EF model or is it possible to use both ? Also taking advantage, there is the possibility of using only the domain and mapping by Map of each class so that does not pollute the code of the Domain class ?
Thanks for the help, I did not answer before, because I was on holiday kkk. There is only one part that I still don’t understand very well, I use the virtual public to access the properties of the associated table from there, right ? Because as I said putting the Responsavelid I am setting the foreign key, will see an int if I access it, while in virtual access the "object" itself, correct? In this case, I need to have both since it is necessary I define the foreign key or just leaving the virtual and mapping as foreing key an attribute is also valid?
– Weslley_51