How to add several custom fields to a BO


Author
Message
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
I am attempting to add several custom fields to a BO. Following the instructions in the tutorial, you need to add GetCustomBindablePropertyDescriptors override for the property. What do you do if you have 4 properties (or any number larger than 1?



A second question is related to best practices. I have a linking table, I.e. it links rows from two different tables, say WidgetsID to a FactorID. I want to be able to show the widgets at a factor, and be able to provide some details about the widget. Is it a good idea to use custom properties in the linking BO to do this. I.e. the linking BO will have three fields, the pk field, the WidgetID field and the FactorID field. Is is a good idea to add a WidgetName and WidgetDescription custom field, that use ExecuteScalar() to retreive the name and description using the current row WidgetID? If it isn't a good idea, why? And is the alternative to use a BO to a view?



Thanks!
Replies
Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
You don't need an interface in this case as you would have to re-write the code in every BO that implemented it.  However, you can inherit the BusinessLayer.  Just create your own BO and then when you create a new business object, just change the inherits to your business layer class and it will use all of your modified code and features:

Public Class MyCustomBusinessLayer
    Inherits MicroFour.StrataFrame.Business.BusinessLayer

   '-- Add Your Stuff
End Class

Then when you create a new business object through the Add Item template, you will need to adjust the inherits the first time (you will notice that the only BO code file that has a inherits declaration is in the MyBo.vb file.  This is so the BO Mapper does not overwrite your inherits statement when changed to use your BO class.  It would look like this in this example:

<Serializable()> _
Public Class MyNewBO
    Inherits MyCustomBusinessLayer
   '-- all of the other template code will be here...
End Class

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Actually, the reason I was looking at an interface was that I have another class (a user control actually) that would interface with the common functionality of the special BOs. I.e. I need to reference the Interface in the other class, so I can call the known methods (the BOs will all have sequencing functionality, like MoveItemUp, MoveItemDown, etc.). Each BO would implement the methods as needed by the particular table.

What I ended up doing was to just create two variables, one as a BusinessLayer item and one as my interface item (IParentSequencerBO). Then provided a single public property for the BusinessLayer variable, set the interface variable to the same object. It seems to be working great. E.g. below in case my narrative is confusing.


Public Class MyClass

private _bo as Microfour.StrataFrame.Business.BusinessLayer
private _seqBO as IParentSequenceBO
private _idField as String

Public Property IDField(fieldName as string)
Get
IDField = _idField
End Get
Set(ByVal value As string)
_idField=value
End Set
End Property

Public Property BO As Microfour.StrataFrame.Business.BusinessLayer
Get
BO = _bo
End Get
Set(ByVal value As Microfour.StrataFrame.Business.BusinessLayer)
_bo = value
_seqBO = value
End Set
End Property

Public Sub MoveDown()
'-- Call a method of the BusinessLayer
Dim id As Int32 = _bo.Item(Me.IDField)

'-- Call a method define by the interface
_seqBO.MoveItemDown(id)
End Sub
End Class


If you have a better idea, I'm all ears.
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
OK, what is the correct tag for code snippets. Obviously, the one's I'm using are correct. Sad
Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
What you are doing will definitely work.  There are two other things that you could do.  First, tack this on to my first example...create your own interface, as you have, and then associated this interface with your custom BusinessLayer class.  This is more structured and will be much easier to work with as your application grows.

Public Class MyCustomBusinessLayer
    Inherits MicroFour.StrataFrame.Business.BusinessLayer
    Implements IParentSequenceBO
   '-- Add Your Stuff
End Class

As for your code snippet, I edited your post and then saved and it worked. There could be underlying characters that are being pasted in with your code causing the problem.  One thing to do is to paste it into notepad first then copy it from there.  THis way all special characters are stripped.

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
That is exactly what I'm doing. I'm going to have half dozen or so BOs that all have this sequencing functionality. With this interface I can build a reusable UI control/component to re-sequence elements within the BO. Though I might suggest that you provide a IBusinessLayer interface in the future. It would make this sort of thing easier. Then I could just inherit that interface for any of my own and life would be grand BigGrin
Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
I don't think I can explain this properly over the forum, but there is no need for an IBusinessLayer interface.  An interface is not the solution here...you can use the BusinessLayerBase class, which you will find commonly throughout the framework and in typed editors, etc.  This will give you the base functionality and will allow any type of BO to be handed over to a variable or property typed as this...but I still do not see a need for the IBusinessLayer interface. 
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Trent L. Taylor (11/17/2006)
I don't think I can explain this properly over the forum...




I just wrote out a long explanation of why an IBusinessLayer interface would be helpful when I think I get what you are saying about using a concrete class....



So, I create a new class, lets say ParentSequencerBO. This would not hit any tables right (and thus would always have a red X by it in the BO mapper)? it would look something like:





Public MustInherit Class ParentSequencerBusinessLayer

Inherits BusinessLayer



' Abstract methods...but they could be actual methods too, if code

' could be generalized

Public MustOverride Sub MoveItemUp()

Public MustOverride Sub MoveItemDown()



End Class





Then I would derive my actual BOs from it:





Public Class ProcessStepBO

Inherits ParentSequencerBusinessLayer



Public Overrides Sub MoveItemUp()

' ...code

End Sub

Public Overrides Sub MoveItemDown()

'....code

End Sub

End Class





Then my User control would reference the abstract class ParentSequencerBusinessLayer and I'm good. See, I think you got it across here in the forum (if I'm getting it)! Tongue



P.S. the [codesnippet][/codesnippet] isn't working. I double checked for weird characters, pasted into and out of a text editor...but no joy. Maybe it is user permission thing?
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Threaded View
Threaded View
Greg McGuffey - 19 Years Ago
Trent L. Taylor - 19 Years Ago
Greg McGuffey - 19 Years Ago
                 I will look into the missing help topic. Thanks.
Trent L. Taylor - 19 Years Ago
Greg McGuffey - 19 Years Ago
                         [quote] It just occurred to me, is it better to use...
Trent L. Taylor - 19 Years Ago
                             [quote][b]Trent L. Taylor (11/16/2006)[/b][hr]Going through the BO is...
Greg McGuffey - 19 Years Ago
                                 [quote]This is how the BO internally executes the command right? The...
Trent L. Taylor - 19 Years Ago
Greg McGuffey - 19 Years Ago
Trent L. Taylor - 19 Years Ago
Greg McGuffey - 19 Years Ago
Greg McGuffey - 19 Years Ago
                         What you are doing will definitely work. There are two other things...
Trent L. Taylor - 19 Years Ago
                             That is exactly what I'm doing. I'm going to have half dozen or so BOs...
Greg McGuffey - 19 Years Ago
                                 I don't think I can explain this properly over the forum, but there is...
Trent L. Taylor - 19 Years Ago
                                     [quote][b]Trent L. Taylor (11/17/2006)[/b][hr]I don't think I can...
Greg McGuffey - 19 Years Ago

Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search