This is a migrated thread and some comments may be shown as answers.

Issue with Open Access ORM and IDataErrorInfo

2 Answers 26 Views
Data Access Free Edition
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Lorenzo
Top achievements
Rank 1
Lorenzo asked on 19 Nov 2013, 05:59 PM
Hello,

I found a problem using an example of the Open Access ORM documentation. (http://documentation.telerik.com/openaccess-orm/developers-guide/code-generation/developer-guide-code-generation-implement-idataerrorinfo).

The implementation of the ValidateProperty method in this example has a problem. I tested it on a project by myself and found that if only one property of a business object is checked in this method and the validation of this field fails, all other properties of the object will have the same error message because '_error' field is shared by all of them. You have to initialize the error argument in the ValidateProperty method to empty before you check the properties.

Partial Public Class Category
    Private Sub ValidateProperty(ByVal propertyName As String, ByRef [error] As String)
           [error] = "" 'If you don't do this initialization, all the fields that follow the
                               'last that fails validation
                               'will share the same error message
        Select Case propertyName
            Case "CategoryID"
                If CategoryID < 0 Then
                    [error] = "The identification number of the category cannot be negative"
                End If
            Case "CategoryName"
                If String.IsNullOrWhiteSpace(CategoryName) Then
                    [error] = "You need to provide a name for the category"
                End If
        End Select
    End Sub
End Class


I could be wrong, but that is the way I sort it out.

Thank you,
Lorenzo.

2 Answers, 1 is accepted

Sort by
0
Doroteya
Telerik team
answered on 22 Nov 2013, 03:12 PM
Hello Lorenzo,

Thank you for bringing this issue to our attention.

Indeed, setting [error] to String.Empty at the beginning of the ValidateProperty() method is required in order to provide a different error message for each property, each time an instance of the class is validated. Your remark will be reflected in our documentation with its upcoming update.

Note, however, that the implementation of the ValidateProperty() method can vary depending on the requirements and the complexity of the specific scenario IDataErrorInfo participates in.

If you encounter any other issues in our documentation or if you have technical questions, do not hesitate to get back to us.


Regards,
Doroteya
Telerik
OpenAccess ORM Q3 2013 simplifies your model operations even further providing you with greater flexibility. Check out the list of new features shipped with our latest release!
0
Lorenzo
Top achievements
Rank 1
answered on 23 Nov 2013, 10:46 PM
Hello Doroteya,

thank you for your answer. I came across to this issue because I wanted to use the ErrorProvider component and every time there were a validation error on a field, all the other fields would show the error icon.

Regards,
Lorenzo Martin Edreira
Tags
Data Access Free Edition
Asked by
Lorenzo
Top achievements
Rank 1
Answers by
Doroteya
Telerik team
Lorenzo
Top achievements
Rank 1
Share this question
or