Validation Strategy RRS feed

  • Question

  • I am looking for information on how people are handling business rule (and field validations) using an ADO.NET Data Service wrapped around an Entity Framework object context.

    I have seen numerous posts/articles/etc that seem to be fine with just throwing an exception.  Using this type of approach would produce client applications that would require the user to hit save and get one error at a time (save, error, fix error, save, new error, fix new error, etc).  Initially I was hoping to just throw a FaultException with my own serializable objects during the Context.SaveChanges virtual like so:

    public class MyListOfErrors
    	public List<MyError> Errors { get; set; }
    	public MyListOfErrors()
    		Messages = new List<MyError>();
    public class MyError
    	public string Field { get; set; }
    	public string Message { get; set; }
    	public MyError(string field, string message)
    		Field = field;
    		Message = message;
    throw new FaultException<MyListOfErrors>(listOfErrors, "Validations Failed");
    The problem I have though is that the ADO.NET Data Service will only throw back a DataServiceException.  Inside of the DataServiceException I can see that the Response property does have a ChangeOperationResponse but unfortunately the only information I can get out of it is:

    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
    <message xml:lang="en-US">An error occurred while processing this request.</message>
    <message>Validations Failed</message>
    <type>System.ServiceModel.FaultException`1[[MyNameSpace.MyListOfErrors, MyNameSpace, Version=, Culture=neutral, PublicKeyToken=null]]</type>
    <stacktrace>...stack trace here...</stacktrace>
    Why is this inconsistent with the WCF standard of preferring Faults to be passed back over the wire?
    Does anyone know of an alternative rather than implementing my own CRUD services (plus everything else the service gives us, filter, sort etc)?
    Wednesday, August 26, 2009 6:53 PM

All replies

  • It sounds to me like you might benefit from having real business objects on the client.  In my code I accomplish this using T4 templates to generate business-rule friendly proxy classes rather than use the poco-style proxies generated from data services.


    Monday, September 7, 2009 2:29 AM