I know it only allows the class to set it, but what is the point?
How do I solve the problem of having readonly ids?
Say I have a person class
public class Person
{
public string Name { get; set; }
public int Id { get; private set; }
public int Age { get; set; }
}
And this is in a Entities.dll, used by a GUI, BL and DAL The GUI calls the BL
List<Person> p = BL.PeopleBL.GetPeople();
For the sake of the example calls the DAL
...
while(dr.read())
{
returnPersonList.add( new Person{ Age=dr.GetInt32(1), Id=dr.GetInt32(0), Name=dr.GetString(2)})
}
...
of course I cannot do that cause Id is a private set; What is the proper way to do this?
How can I let the BL/Dal set the Id, but not on the GUI?
Or is this not even the proper use of a private set?
I just wanted to add that this is your typical DB app, where the pk is the Id and should not be changed( only by the BL/DAL)
Regards
_Eric