Filling the entire row is not a good idea in this scenario. You can take two approaches. First, I would put the load on SQL Server and include the field in the query versus making another trip to the server. The fewer trips the better, and this can always be included in your query if necessary:
SELECT Staff.*, SchoolTitles.TitleName FROM Staff INNER JOIN SchoolTitles ON Staff.ForeignKey = SchoolTitles.PrimaryKey
Using this, you can create a custom property in the BO that uses the TitleName (which will already be retrieved from the initial query:
Public Readonly Property SchoolTitleName As String
Get
Return CType(me.CurrentRow.Item("TitleName"), String)
End Get
End Property
Trent, I'm getting back to testing this approach to custom field properties and have a few questions/problems. I added a new field to a BO.Fill method and added a custom property as below in my ClaimBO:
Public Sub FillAll() Me.FillDataTable("Select Claim.*, ses_Date from Claim left outer join Session " & _"on Claim.cla_FK_Session = Session.ses_PK")End Sub''' <summary>''' Add looked up Session Date from Session table''' </summary><Browsable(
False), _BusinessFieldDisplayInEditor(), _
Description(
"Session Date"), _DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
Public ReadOnly Property ses_Date() As System.DateTimeGetReturn CType(Me.CurrentRow.Item("ses_Date"), Date)End GetEnd PropertyProtected Overrides Function GetCustomBindablePropertyDescriptors() As MicroFour.StrataFrame.Business.FieldPropertyDescriptor()Return New FieldPropertyDescriptor() {New ReflectionPropertyDescriptor("ses_Date", Me.GetType())}End Function Unfortunately I get an error when adding a new record on my ClaimSFMaintentanceForm after loading the form with my ClaimBO.FillAll() method:
KeyNotFoundException
The specified key was not present in the dictionary.
Source : MicroFour StrataFrame Base
Stack Trace:
at MicroFour.StrataFrame.Data.DataBasics.GetFieldFromDictionaryOrdinalKey[T](Dictionary`2 dict, String key)
at MicroFour.StrataFrame.Data.DataBasics.InitializeNewRow(DataRow NewDataRow, StringCollection IgnoredFields, Dictionary`2 FieldNativeTypes)
at MicroFour.StrataFrame.Business.BusinessLayer.NewRow()
at MicroFour.StrataFrame.Business.BusinessLayer.Add(Boolean CheckSecurity)
at MicroFour.StrataFrame.UI.Windows.Forms.BaseForm.Add(Boolean CheckSecurity)
....
If I don't load the ClaimSFMaintanenceForm with any records and press New, I get a similar error:
BusinessLayerException
An error occurred while refreshing the data from field 'ClaimBO.ses_Date' to property 'Text' on control 'Textbox5.'
TargetInvocationException
Exception has been thrown by the target of an invocation.
ArgumentException
Column 'ses_Date' does not belong to table Claim.
Source : MicroFour StrataFrame Business
Stack Trace:
at System.Data.DataRow.GetDataColumn(String columnName)
at System.Data.DataRow.get_Item(String columnName)
at TBNet.ClaimBO.get_ses_Date() in E:\TBNet\TBNet\BOs\ClaimBO.vb:line 85
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
....
The second error says "ses_Date does not belong to table Claim"... which is true unless my FillAll() method is used to fill the underlying table. I assume this has something to do the with "dictionary" mentioned in the first error... but I need some additional guidance. My impression is that I need to do more to fully inform the default SF methods / engine about this field that doesn't exist on the source Claim table in the database.
TIA,
Larry