Question

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?

Was it helpful?

Solution

You can do data validation in linq-to-entities, but it is different from linq-to-sql, as you've discovered. See the following link:

data validation in linq-to-entities

OTHER TIPS

Check:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top