views:

601

answers:

2

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?

+1  A: 

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.

Jonathan Parker
That is what I was thinking about, however what exactly should I check, what methods and properties provided by a dataset should I use. I am interested in a datarow especially.
iulianchira
I've added a link to a code project article that might help.
Jonathan Parker
I still think validation does not belong in our data access code. Linq to SQL is a special case because it maps business object to our database. Datasets, on the other hand, is pure data access code.
Thomas Eyde
Yes, however the fact that iulianchira has decided to use datasets makes me think (maybe wrongly) that he's not up to speed with Linq2Sql.
Jonathan Parker
The application is for a school project, and ADO.NET is a requirement.
iulianchira
+1  A: 

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.

Thomas Eyde