Where does one put validation for external content types? Let's say one field on my ECT represents an email address that must be unique in our system. Where would I put the validation that checks to see that someone hasn't submitted an instance of the ECT with a duplicate email address? How do I bubble up validation errors so they're displayed in the SharePoint UI?
Well it depends? It can be checked in your data source (within the database / stored proc / WCF) which is where it should be as that's business logic that's domain specific. You ~could~ implement it in your custom operators, but I'm not sure that's a good idea as the reuse isn't there (if other apps are using the same data source).
Let's say my Creator method on my BCS entity has code within it that detects that it was passed a duplicate email address, how would I alert the end user of this validation error? I see no way to return any sort of status or anything from my Creator method that would reject the form submission and display a validation error message. If I were using a totally custom application page for the data entry, I'd use the built-in ASP.NET validation server controls (like CustomValidator) which handles this sort of thing.– SPMetaMay 12, 2010 at 12:34
1Good question... I'd throw an exception with a message. I haven't tried this but I'd expect there would be a BCS specific exception you could throw similar to how you validate custom field types. May 14, 2010 at 10:14
As painful as it is List Validation Settings, as defined in List Settings, is actually not available for ECT, either is versioning or ratings or a whole host of other features that are applicable to lists.
As Andrew suggested though you might have to do it on the back end because there is no out of the box way to do it currently.
From my POV, it is a biz logic thing that should be closer to the data source. Think of SharePoint ECT's as more of the presentation layer. May 12, 2010 at 10:34
My understanding is you apply custom validation through the InfoPath form validation. First you generate InfoPath forms for an external list in SPD. You can then apply the validation to individual fields using InfoPath validating event and code behind.
I agree with Andrew that it would be nice to be able to apply the validation in code by throwing an exception either directly from the DB or from the .NET code. Problem is, I wasn't able to find the exception type that would display the way validation errors are displayed in the UI. Throwing an exception that generates a yellow screen of death (or a web part/list failed error message) is not an option.
I have posted an answer to a similar question on stackoverlfow.com: https://stackoverflow.com/questions/2760774/validation-for-sharepoint-2010-external-lists-external-content-types/3014365#3014365