Possible with Validation Block??

Topics: Building and extending application blocks, General discussion, Validation Application Block
Aug 20, 2009 at 4:22 PM

Hi,

I have a collection of MyObjects.  Field1 and Field2 of MyObject form part of the primary key used on the database. 

public class MyObject
{
    public string Field1 { get; set; }
    public string Field2 { get; set; }

    public string Field3 { get; set; }
}

Is it possible to validate the collection using the Validation Block, so that the validation results returned for each failing object are something along the lines of "Duplicate Key Detected for Field1 + Field2 key"?

I don't believe it is, but I want to check before I implement anything.  Ideally I am looking to make the configurable via XML.

e.g.

 

<UniqueKeys>
    <UniqueKey Name = "UniqueKey1">
        <Field Name = "Field1" />
        <Field Name = "Field2" />
    </UniqueKey>
</UniqueKeys>

 

Thanks,

Ben.

 

 

Aug 24, 2009 at 6:03 AM

Yes. That would also be my thought. I was thinking maybe the validation part would be possible by implementing your own validator, but I'm not totally sure if that will work.

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Aug 25, 2009 at 12:33 AM

It is possible to validate a collection of object using VAB but since there's no built-in validator in entlib that can handle the validation logic that you want, you would definitely need to create your own validator.  You can then create your own validation message.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com