Foreign Key Field Description


Author
Message
ChanKK
ChanKK
Advanced StrataFrame User (622 reputation)Advanced StrataFrame User (622 reputation)Advanced StrataFrame User (622 reputation)Advanced StrataFrame User (622 reputation)Advanced StrataFrame User (622 reputation)Advanced StrataFrame User (622 reputation)Advanced StrataFrame User (622 reputation)Advanced StrataFrame User (622 reputation)Advanced StrataFrame User (622 reputation)
Group: Forum Members
Posts: 190, Visits: 1.3K
Hi,

I have table employee (EmployeeBO) with field

employeeNo, employeeName.



I have txn table sale (SalesBO) with field

SalesNo, Date, EmployeeNo, Qty, Price, Total



I would like like to list table employee in editable GridView with columns



SalesNo, Date, EmployeeNo, EmployeeName, Qty, Price, Total



In order to achieve this, I added custom bindable field - EmployeeName to SalesBO, and retrieve it from employeeTable whenever required. I found that it is really killing my application performance.



May I know how should I amend it to get back performance?



Thank you

Replies
Larry Caylor
Larry Caylor
StrataFrame VIP (1.8K reputation)StrataFrame VIP (1.8K reputation)StrataFrame VIP (1.8K reputation)StrataFrame VIP (1.8K reputation)StrataFrame VIP (1.8K reputation)StrataFrame VIP (1.8K reputation)StrataFrame VIP (1.8K reputation)StrataFrame VIP (1.8K reputation)StrataFrame VIP (1.8K reputation)
Group: Awaiting Activation
Posts: 592, Visits: 3.7K
Chan,

Edhy is right on, I use this approach for custom fields all the time. Shortly after the original version of SF was released it was enhanced to save only the fields contained in the BOs AllFieldNames list (The AllFieldNames contains the fields defined in BO mapper). This allows you to add any fields you want in a custom fill method, it just won't be persisted to the database. For example, assume that I have an order table that contains the foreign key for the customer table and I want to display the customers name as a custom field in my order BO. My OrderBO custom fill method would look someting like this

Public Sub FillOrder(ByVal OrderID As Integer)
  ' Establish locals.
  Dim sqlCmd As New SqlCommand
  ' Build the command
  With sqlCmd
    .CommandText =
"SELECT " & Me.AllFieldNames & ",cu_Name " & _
   
"FROM " & Me.TableNameAndSchema & " " & _
   
"JOIN Customer ON cu_pk = or_cu_pk " & _
   
"WHERE or_pk = @OrderID "
   
.Parameters.AddWithValue("@OrderID", OrderID)
  End With
  ' Fill object.
  Me.FillDataTable(sqlCmd)
End Sub

The custom field on my OrderBO would look like

<Browsable(False), _
BusinessFieldDisplayInEditor(), _
Description("Customer Name"), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
Public ReadOnly Property cust_CustomerName() As String
  Get
  ' Check to see if datatable contains the custom field in
  ' case object was filled by a method that doesn't contain the field.

   
If Me.CurrentDataTable.Columns.Contains("cu_Name") Then
     
If Not TypeOf (Me.CurrentRow.Item("cu_Name")) Is DBNull Then
       
Return CStr(Me.CurrentRow.Item("cu_Name"))
     
Else
       
Return ""
     
End If
   
Else
     
Return ""
   
End If
 
End Get
End Property

When I go to save the OrderBO object, only the fields defined in the AllFieldNames list will be saved, any fields that I've added will be ignored.

-Larry


Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hey Larry, thanks for the code, I like your approach to make sure that the custom field exist in the data table:



If Me.CurrentDataTable.Columns.Contains("cu_Name") Then....




Updating my code now... Hehe

Edhy Rijo

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