3
When I create domains, I usually create a parameterized constructor for the same:
namespace Models
{
public class Unity
{
public string Abreviation { get; set; }
public string Description { get; set; }
public Unity (string abreviation, string description)
{
Abreviation = abreviation;
Description = description;
}
public Unity ( ) { }
}
}
This way the user of the class has the option to pass the value of the properties at the same moment of the instantiation of the object. Or pass them later through the setters.
This is valid in the RU?
I don’t think there’s any need, since you can do it
var unity = new Unity{Abreviation = "un", Description = "unity"};
. But how so if it is valid in EF? Could explain better?– Randrade
It is valid yes ... !!! This goes for every developer, or development group, or rule followed. But this is no problem
– user46523
I would say it’s something useless. I can do it like this:
var unity = new Unity { Abbreviation = abbreviation, Description = description };
– Leonel Sanches da Silva
@Ciganomorrisonmendez because useless, there is development with DDD that this is more than valid ... because useless ?
– user46523
This may help you or perhaps answer: http://answall.com/q/73530/101 EF does not have a specific need for this. The second empty constructor makes the first unnecessary, as already reported by Randrade. If only the first would be different.
– Maniero
@John DDD. It’s explained.
– Leonel Sanches da Silva
@Randrade I mean, if I pass the values of the properties through the builder, give an Add and have saved? Will the EF save normally? I did not remember this syntax of C#, as I came from other languages that do not have the same resource, I ended up bringing together some habits.
– Matheus Saraiva
I did not go deeper because it is a subject that already has answers on the site.
– Randrade