StrataFrame Forum

Creating a BO Base Class...?

http://forum.strataframe.net/Topic18372.aspx

By Edhy Rijo - 8/7/2008

I am working on a project which requires the use of GUID PKs, I am following the good samples in this thread: http://forum.strataframe.net/Topic15854-6-3.aspx?Highlight=NewSequentialId

I created a a base BO class named ApplicationBaseBusinessClass.vb with the following code:

Imports MicroFour.StrataFrame.Business

Imports System.ComponentModel

Imports System.Runtime.Serialization

Public Class ApplicationBaseBusinessClass

Inherits MicroFour.StrataFrame.Business.BusinessLayer

#Region " Private Fields "

Private _PrimaryKeyIsAutoIncremented As Boolean = False

Private _PrimaryKeyIsUpdatable As Boolean = True

#End Region

#Region " Public Properties "

''' <summary>

''' Gets or sets a value that determines whether the primary key for this business object is

''' auto-incremented within the data source (assigned by the database rather than by the

''' client).

''' </summary>

<Category(EDITOR_CATEGORY_CRUD), _

DefaultValue(False)> _

Public Overrides Property PrimaryKeyIsAutoIncremented() As Boolean

Get

Return _PrimaryKeyIsAutoIncremented

End Get

Set(ByVal value As Boolean)

_PrimaryKeyIsAutoIncremented = value

End Set

End Property

''' <summary>

''' Determines if the primary key field is updatable. This property allows primary key fields that are not auto-incrementing to be used while

''' preventing an update error if the field is not updatable (i.e. Guid Primary Keys).

''' </summary>

<Category(EDITOR_CATEGORY_CRUD), _

DefaultValue(True)> _

Public Overrides Property PrimaryKeyIsUpdatable() As Boolean

Get

Return _PrimaryKeyIsUpdatable

End Get

Set(ByVal value As Boolean)

_PrimaryKeyIsUpdatable = value

End Set

End Property

#End Region

#Region " Overridable Subs "

Protected Overrides Sub OnSetDefaultValues()

MyBase.OnSetDefaultValues()

If Me.PrimaryKeyIsUpdatable = True AndAlso Me.PrimaryKeyIsAutoIncremented = False Then

'-- Set Value for GUID PK

'-- Get a reference to the property descriptor (which doesn't use reflection)

Dim loFieldPropDescriptor As FieldPropertyDescriptor = Me.GetPropertyDescriptor(Me.PrimaryKeyField)

'-- If the PK type is a Guid then Generate a Sequential GUID to prevent Index fragmentation

If loFieldPropDescriptor.PropertyType Is GetType(Guid) Then

loFieldPropDescriptor.SetValue(Me, ezCallTrack.Basics.NewSequentialID)

End If

End If

End Sub

#End Region

End Class

I then changed the Ingeritance in my BizCustomer.vb class from:

Inherits MicroFour.StrataFrame.Business.BusinessLayer

To:

Inherits ezCallTrack.Business.ApplicationBaseBusinessClass

Now I am getting a compiler error in my BizCustomer.vb "Too many arguments to Public Sub New()", this is the code created by the BOM that generates the error:

''' <summary>

''' Initializes a new instance of the bizCustomers class.

''' </summary>

''' <param name="info">The SerializationInfo for the object.</param>

''' <param name="context">The StreamingContext for the source stream.</param>

''' <remarks></remarks>

Protected Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext)

MyBase.New(info, context)

'This call is required by the Component Designer.

Me.InitializeComponent()

'-- Add the necessary handlers

Me.AddHandlers()

End Sub

Here is the code for the BO bizCustomer.vb

Imports System.Data

Imports System.Data.SqlClient

Imports System.Runtime.Serialization

<Serializable()> _

Public Class bizCustomers

Inherits ezCallTrack.Business.ApplicationBaseBusinessClass

#Region " Constructors "

''' <summary>

''' Initializes a new instance of the bizCustomers class.

''' </summary>

''' <remarks></remarks>

<System.Diagnostics.DebuggerNonUserCodeAttribute()> _

Public Sub New()

MyBase.New()

'This call is required by the Component Designer.

Me.InitializeComponent()

'-- Add the necessary handlers

Me.AddHandlers()

End Sub

''' <summary>

''' Initializes a new instance of the bizCustomers class.

''' </summary>

''' <param name="Container">The IContainer to which this object will be added.</param>

''' <remarks></remarks>

<System.Diagnostics.DebuggerNonUserCodeAttribute()> _

Public Sub New(ByVal Container As System.ComponentModel.IContainer)

MyBase.New()

'This call adds the component to the given container.

Container.Add(Me)

'This call is required by the Component Designer.

Me.InitializeComponent()

'-- Add the necessary handlers

Me.AddHandlers()

End Sub

''' <summary>

''' Initializes a new instance of the bizCustomers class.

''' </summary>

''' <param name="info">The SerializationInfo for the object.</param>

''' <param name="context">The StreamingContext for the source stream.</param>

''' <remarks></remarks>

Protected Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext)

MyBase.New(info, context)

'This call is required by the Component Designer.

Me.InitializeComponent()

'-- Add the necessary handlers

Me.AddHandlers()

End Sub

''' <summary>

''' Adds the necessary handlers for the bizCustomers class.

''' </summary>

''' <remarks></remarks>

Private Sub AddHandlers()

AddHandler Me.CheckRulesOnCurrentRow, AddressOf bizCustomers_CheckRulesOnCurrentRow

AddHandler Me.SetDefaultValues, AddressOf bizCustomers_SetDefaultValues

End Sub

#End Region

#Region " Data Retrieval Methods "

#End Region

#Region " Event Handlers "

''' <summary>

''' Checks the business rules on the current row

''' </summary>

''' <param name="e"></param>

''' <remarks></remarks>

Private Sub bizCustomers_CheckRulesOnCurrentRow(ByVal e As MicroFour.StrataFrame.Business.CheckRulesEventArgs)

End Sub

''' <summary>

''' Sets the default values for a new row

''' </summary>

''' <remarks></remarks>

Private Sub bizCustomers_SetDefaultValues()

End Sub

#End Region

End Class

What am I doing wrong here?

P.S.

Sorry for the long post.

By Ivan George Borges - 8/7/2008

Hey Edhy.

Aren't you missing the Constructor Overloads in your base class?

#Region " Constructors "

    ''' <summary>
    ''' Initializes a new instance of the ApplicationBaseBusinessClass class.
    ''' </summary>
    ''' <remarks></remarks>
    <System.Diagnostics.DebuggerNonUserCodeAttribute()> _
    Public Sub New()
        MyBase.New()
        'This call is required by the Component Designer.
        Me.InitializeComponent()

        '-- Add the necessary handlers
        Me.AddHandlers()
    End Sub

    ''' <summary>
    ''' Initializes a new instance of the _BaseBO class.
    ''' </summary>
    ''' <param name="Container">The IContainer to which this object will be added.</param>
    ''' <remarks></remarks>
    <System.Diagnostics.DebuggerNonUserCodeAttribute()> _
    Public Sub New(ByVal Container As System.ComponentModel.IContainer)
        MyBase.New()
        'This call adds the component to the given container.
        Container.Add(Me)
        'This call is required by the Component Designer.
        Me.InitializeComponent()
        '-- Add the necessary handlers
        Me.AddHandlers()
    End Sub

    ''' <summary>
    ''' Initializes a new instance of the ApplicationBaseBusinessClass class.
    ''' </summary>
    ''' <param name="info">The SerializationInfo for the object.</param>
    ''' <param name="context">The StreamingContext for the source stream.</param>
    ''' <remarks></remarks>
    Protected Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext)
        MyBase.New(info, context)
        'This call is required by the Component Designer.
        Me.InitializeComponent()
        '-- Add the necessary handlers
        Me.AddHandlers()
    End Sub

    ''' <summary>
    ''' Adds the necessary handlers for the ApplicationBaseBusinessClass class.
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub AddHandlers()
        AddHandler Me.CheckRulesOnCurrentRow, AddressOf ApplicationBaseBusinessClass_CheckRulesOnCurrentRow
        AddHandler Me.SetDefaultValues, AddressOf ApplicationBaseBusinessClass_SetDefaultValues
    End Sub

#End Region

And, by the way, you might want you event handlers too:

#Region " Event Handlers "

    ''' <summary>
    ''' Checks the business rules on the current row
    ''' </summary>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub ApplicationBaseBusinessClass_CheckRulesOnCurrentRow(ByVal e As MicroFour.StrataFrame.Business.CheckRulesEventArgs)

    End Sub

    ''' <summary>
    ''' Sets the default values for a new row
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub ApplicationBaseBusinessClass_SetDefaultValues()

    End Sub

#End Region

Hope it helps. Wink

By Trent L. Taylor - 8/7/2008

Yup...Ivan nailed it Wink
By Edhy Rijo - 8/7/2008

Hi Ivan,

Now I am confused.  I copied the Constructors Overloads and get more compiler errors.

Can you please list the steps to create a base BO class?

By Trent L. Taylor - 8/7/2008

It is a standard .NET inheritance issue.  Refer to the StrataFlix sample on how to create a base class and then inherit from that class.  It sounds like the problem you are having is a direct inheritance issue...the constructors are protected (even when they are declared public) when inherited.  Without debuging your code (which is not that easy via the forum) I can't tell you exactly where your problem is...but I do know that this is a standard .NET inheritance issue (been there before Wink
By Edhy Rijo - 8/7/2008

Trent, Ivan,

Thanks for the input. 

My error was at the creation of the Base BO class, I did not used the SF BO Class, just added a regular class and then manually added all the code which messed everything else.

I re-created it with the proper steps and now it is working fine.  This is one of those days where you miss simple things w00t