I am delevelopring my first MVC application and I am using a classic ADO.NET dataset as a model. The guide I am following is the NerdDinner ASP.NET MVC Tutorial and it mentions a GetRuleViolations() method for a Linq To SQL model. I would like to have a similar method to check that a datarow is valid after editing. How could I do such a thing?
Datasets are disconnected. As such they don't support validation rules unless you add constraints manually.
Edit: From the link:
We’ll implement IsValid and GetRuleViolations() by adding a “partial class” to our project. Partial classes can be used to add methods/properties/events to classes maintained by a VS designer (like the Dinner class generated by the LINQ to SQL designer) and help avoid the tool from messing with our code.
You could do something similar with a typed dataset.
See this link on validation with typed datasets.
I guess you should use the dataset for data transfer only. Not for business rule validation. In this way you can still follow the tutorial and keep the repository. But replace all Linq to SQL code inside of the repository with your own dataset code.
Your business objects will be the ones implementing the GetRuleViolation()
method.