Exception with Extended Properties


Author
Message
Ertan Deniz
Ertan Deniz
StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)
Group: Forum Members
Posts: 163, Visits: 493
I had thought that I had to write for every property of a class to ensure specified column exist in CurrentDataTable.

But It was only for extended properties. So, It is not hard to write.

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
No, not really.  What do you mean?  I already gave you my comment on the previous post. Smile
Ertan Deniz
Ertan Deniz
StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)
Group: Forum Members
Posts: 163, Visits: 493
Any comment ?
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Any comment ? I 'm trying to find easy way ? (Shared) Central point to write the code. (EnsureColumnsExist)

I generally do this immediately after calling a Fill ... or even in some cases an Add since those columns would not exist on the Add.  This really is up to you and depends on if this is an isolated element of a single maintenance form or will happen for the entire BO no matter where it is used.

If it is the latter, then you may want to override the FillDataTable method on your BO.  Then call this method after you call the MyBase.FillDataTable(...) method. 

Ertan Deniz
Ertan Deniz
StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)
Group: Forum Members
Posts: 163, Visits: 493
Any comment ? I 'm trying to find easy way ? (Shared) Central point to write the code. (EnsureColumnsExist)
Ertan Deniz
Ertan Deniz
StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)
Group: Forum Members
Posts: 163, Visits: 493
Where is the place of this method called in the code ? You said when referencing a column.

Should you give me an explanation ? 

Ertan Deniz
Ertan Deniz
StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)
Group: Forum Members
Posts: 163, Visits: 493
Thanks.
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Well, I see your point, and this is actually by design.  You are wanting to perform a query, and then the internal ADO.NET table to automatically have all of the columns for the table.  This is not how the logic of a BO works.  It expects those columns to be included within the query or to be defined.  In our medical software, we actually have a shared method that ensures that columns and their default values exist in the case that we attempt to reference it, etc.  It looks something like this:

    ''' <summary>
    ''' Ensures that the column specified exists within the table.
    ''' </summary>
    ''' <param name="table"></param>
    ''' <param name="columnName"></param>
    ''' <param name="columnType"></param>
    ''' <param name="defaultValue"></param>
    ''' <remarks></remarks>
    Public Shared Sub EnsureColumnExists(ByVal table As DataTable, ByVal columnName As String, ByVal columnType As System.Type, ByVal defaultValue As Object)
        '-- Establish Locals
        Dim col As DataColumn
        Dim columnFound As Boolean = False

        '-- Cycle through all of the columns so we can test on a case-insensitive basis
        For Each col In table.Columns
            '-- Check to see if the column name matches
            columnFound = col.ColumnName.Equals(columnName, StringComparison.OrdinalIgnoreCase)

            '-- If the column was found, exit
            If columnFound Then Exit For
        Next

        '-- See if there is any reason to continue
        If columnFound Then Exit Sub

        '-- If we make it to this point, then we have a hit
        col = New DataColumn(columnName, columnType)
        col.DefaultValue = defaultValue

        '-- Add the column to the table
        table.Columns.Add(col)
    End Sub


Ertan Deniz
Ertan Deniz
StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)StrataFrame User (179 reputation)
Group: Forum Members
Posts: 163, Visits: 493
protected override FieldPropertyDescriptor[] GetCustomBindablePropertyDescriptors()

{

return new FieldPropertyDescriptor[]

{

new ReflectionPropertyDescriptor("ClientAccountName", typeof(Companies)),

new ReflectionPropertyDescriptor("GroupName", typeof(Companies))

};

}

I 've written the code necessary for the extended properties. The problem is that When we does not select any property (predefined or exteneded) with our query. Business object's table contains only selected columns. Business object is bound to a grid through BBS. Business object contains all the property definitions but table contains only selected ones. This is the central of the problem. After selecting a record on the grid, When we press a button, an exception is thrown. This exception is catched by the InvalidRowException event of the Devexpress Grid. Internally, there is an access to the properties of the business object that is not selected to be shown on the grid. We don't select them because there is no need to show.

This is the my case in detail.

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Binding requires that you provide a type descriptor...I recommend doing a search on GetCustomBindablePropertyDescriptors....there should be a ton of posts on this.  Bottom line is that if you attempt to bind to a column that does not have a descriptor, you will get an error.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search