Results 1 to 4 of 4

Thread: OnPropertyChanged([property] As String)

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2009
    Location
    sydney
    Posts
    265

    OnPropertyChanged([property] As String)

    i have an object "Item" (EFW generated) with a string property description. what is the best approach to set its maximum length to 30.
    Code:
     <EdmScalarPropertyAttribute(EntityKeyProperty:=false, IsNullable:=false)>
        <DataMemberAttribute()>
        Public Property Description() As Global.System.String
            Get
                Return _Description
            End Get
            Set
                OnDescriptionChanging(value)
                ReportPropertyChanging("Description")
                _Description = StructuralObject.SetValidValue(value, false)
                ReportPropertyChanged("Description")
                OnDescriptionChanged()
            End Set
        End Property
    here is what i tried, all i need is to trim the value down to 30 charterers

    Code:
    Partial Public Class Item
        '<StringLength(30)>
        'Public Property Description() As Global.System.String
        Protected Overrides Sub OnPropertyChanged([property] As String)
            'MyBase.OnPropertyChanged([property])
            If [property] = "Description" And Me.Description.Trim.Length > 30 Then ' ************
                oCom.MSG(Me.Description)
                Me.Description = Me.Description.Substring(0, 30)
            End If
    
        End Sub
    
    
    
    End Class

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: OnPropertyChanged([property] As String)

    Shouldn't you be creating a metadata class and applying the StringLength attribute to that property that way?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2009
    Location
    sydney
    Posts
    265

    Re: OnPropertyChanged([property] As String)

    Thanks for the tip, i tried that but still get the truncation error, i looked at the SQL insert statement and it had the full description

    Code:
    <MetadataType(GetType(itemMetadata))>
    Partial Public Class Item
    
    End Class
    
    Class itemMetadata
        <StringLength(30)>
        Public Property Description() As Global.System.String
    End Class

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2009
    Location
    sydney
    Posts
    265

    Re: OnPropertyChanged([property] As String)

    this seems to work
    Code:
    Partial Public Class Item
        Protected Overrides Sub OnPropertyChanged([property] As String)
            Try
                'MyBase.OnPropertyChanged([property])
                If [property] = "Description" And Not Me.Description.Equals(Nothing) Then
                    If Me.Description.Trim.Length > 30 Then
                        oCom.MSG(Me.Description)
                        Me.Description = Me.Description.Substring(0, 30)
                    End If
    
                End If
            Catch ex As Exception
    
            End Try
    
        End Sub
    End Class

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width