I would like to implement some business rule validation like Scott Guthrie did in his MVC Nerddinner tutorial (http://nerddinnerbook.s3.amazonaws.com/Part3.htm), but I'm running into a problem trying to do so.
Scott was using Linq to SQL in his tutorial. He creates partial classes for his data objects, and then he implements a partial method called OnValidate(), which, according to him, is a hook that gets ran when data is persisted to the database for a given data object.
public partial class Dinner {
partial void OnValidate(ChangeAction action) {
if (!IsValid)
throw new ApplicationException("Rule violations prevent saving");
}
}
My problem is that I am using Linq to Entities and apparently there is no "hook" method like the one above that one can use, or at least I can't find it if there is one. Can anyone throw me a bone on how to go about doing this with Linq to Entities?