Dynamic Data - Extending validation

Posts   
 
    
Posts: 254
Joined: 16-Nov-2006
# Posted on: 19-Sep-2008 22:59:56   

In this video

http://www.asp.net/learn/3.5-sp1/video-292.aspx

Scott discusses how to write your own business logic validation through a partial class for products which uses a partial method OnProductNameChanging. How is this possible with the LLBLGEN model as I don't see any partial method with this name?

Obviously I can use simply attributes from the System.ComponentModel.DataAnnotations namespace e.g. Range to specify ranges for values however I'd like to put more complex validation by writing code.

I tried something like this

    protected override bool OnValidateFieldValue(int fieldIndex, object value)
    {
        if ((Int32)Northwind.ProductFieldIndex.Name  == fieldIndex)
        {
            if (!value.ToString().StartsWith("ABC"))
            {
                throw new ValidationException("Bad ABC");
            }

        }
        return base.OnValidateFieldValue(fieldIndex, value);
    }

However this just threw an exception and didn't get handled by dynamic data to present the message in the ValidationException

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 20-Sep-2008 12:00:20   

I'm moving this to architecture, as dynamic data related problems are really a problem of MS, except if our code crashes.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 254
Joined: 16-Nov-2006
# Posted on: 20-Sep-2008 20:03:34   

I'll raise a thread on this on the MS dynamic data forum and feedback any input here in response to this thread.

Posts: 254
Joined: 16-Nov-2006
# Posted on: 21-Sep-2008 13:16:36   

Hi Frans,

Review the response from David to the thread I created on the MS dynamic data forums.

http://forums.asp.net/t/1322849.aspx

Actually, it looks like it may be an issue with the LLBLGen data source, which is not firing its IDynamicDataSource.Exception event when an error occurs.

Perhaps you can confirm whether this is the case of not?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 22-Sep-2008 10:34:52   

I don't understand... why do I have to raise an event when an exception occurs? (I indeed don't raise events when exceptions occur, that would be weird: they'll never be called anyway, the exception will make the CLR bubble up the exception till a handler is found).

Should the exception also be swallowed or something? I find this a weird way of doing things... similar to winforms databinding where things go seriously wrong if an exception occurs which isn't related to validation: these aren't always bubbled upwards and sometimes get swallowed by winforms controls along the way...

Frans Bouma | Lead developer LLBLGen Pro
Posts: 254
Joined: 16-Nov-2006
# Posted on: 22-Sep-2008 19:00:27   

Hi Frans,

Rather than me copy and paste your response into the MS thread and then MS respond and me paste back into this thread please could you respond directly to MS in the dynamic data forum thread.

Many thanks

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 23-Sep-2008 10:19:01   

Matt, I can't promise to spend time on this really. the point is that supporting dynamic data took some time and having to deal with every little detail they might change/cook up isn't something I really look forward to.

I'll see if I can dig up some documentation about this, but do realize that to be able to support this we have to setup a test scenario first, so we can reproduce exactly what you run into. Also, to be able to raise an event (frowning ) when an exception occurs isn't as simple as it might sound: EVERYWHERE where an exception might occur extra code might be needed to make this happen: if the exception thrown isn't caught, the event can't be raised.

I must say I find that a step too far.

(edit) I've replied there. During the post, I thought of other objections against this which make it even probably impossible to implement this properly.

Sorry.

Frans Bouma | Lead developer LLBLGen Pro