Data stored in relation database with data constraints (for example maximum string property length). Clients use Data Access Library (DAL) to manage the data in ORM manner (repositories + data domain classes)
Where would you personally implement constraints? For example:
Data domain classes:
class Person
{
private string _name;
public string Name
{
get { return _name; }
set { _name = StringHelper.Truncate(value, 50) }
}
...
}
Or may be repository:
PersonRepository {
public void CreatePerson(Person p) {
p.Name = StringHelper.Truncate(p.Name, 50);
...
DataContext.Insert(..);
}
}
Or may be you shall use attributes assigned to data domain classes properties that would be processed in repository methods via reflection for automated string fields truncation.
class Person {
[StringConstraint(MaxLength = 50)]
public string Name { get; set; }
}
PersonRepository::CreatePerson(p) {
EntityHelper.ApplyConstraints(p);
...
}
Or may be something else?
Thank you in advance!