Best practices for retrieving lookup values for foreign keys


Author
Message
Larry Tucker
Larry Tucker
StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)
Group: StrataFrame Users
Posts: 69, Visits: 308
Edhy,

in the BO instance in your form, there is a property where you can tell which fields should be ignored for update

Thanks for jumping in an making the suggestion.  I found the properties (FieldsToExcludeFromInsert and FieldsToExcludeFromUpdate) and filled each with "ses_Date"... but no improvement.  Still thanks for pointing these out.

I think I'm interpeting Trent's original suggestion in an overly optomistic way.  By adding the extra field to my FillAll() method, this only temporarily adds the lookup field (ses_Date) to my ClaimBO.CurrentDataTable.  Even though the field property is defined in the BO, most other times the underlying datatable is filled by built-in SF methods, it will not have this field.  I think that is why the Add method is failing.

Back in VFP I used to used updatable views a lot for this purpose, and would mark only the fields associated with the core table as "Send Updates".  So in this case, I could work with my Claims table (and see the associated ses_date as a readonly lookup field that is not updated).

I can go back to using scalar calls to fill my custom field properties, but it seems like a lot of round trips to the server.  Filling all at once using more complex Fill method calls (with joined lookup tables) seeme like a neat solution.

Larry

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Actually the problem here may be that when you perform a query the ses_date field is there.  But if you have not performed a query and just add a new record, the ses_date field is not within the column collection.  In this case, you need to manually add the column to the CurrentDataTAble.COlumns collection so that your code can reference this field without error.

Since you are getting this error, I would imagine that you are pulling from the strong-typed field property either via binding or in code without having performed a query...and thus the column doesn't exist within the BO.  I have a shared method in our medical software that I use called EnsureColumnExists that I will place in different places depending on what I am trying to accomplish that accepts a BO, field name, and field type and then makes sure that the column always exists so that this error doesn't creep up on you.

Edhy Rijo
E
StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Larry,

Here you can find the shared method Trent is talking about: http://forum.strataframe.net/FindPost16437.aspx

Edhy Rijo

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Thanks, Edhy Wink
Larry Tucker
Larry Tucker
StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)
Group: StrataFrame Users
Posts: 69, Visits: 308
Trent,

Thanks for the explanation and Edhy, thanks for the reference.  I'll give it a try.

Larry

Larry Tucker
Larry Tucker
StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)
Group: StrataFrame Users
Posts: 69, Visits: 308
I think I'm close.  Adding the EnsureColumnExists() call prevents the "Column 'ses_Date' does not belong to table Claim" error as it should.

However, when I add a new record to ClaimBO using an SFMaintenance form, even after making sure the column exists, I am still getting the following:

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)
   at MicroFour.StrataFrame.UI.Windows.Forms.MaintenanceFormToolStrip.cmdNew_Click(Object sender, EventArgs e)
   at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
   at System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)
   at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
   at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
   at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
   at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
   at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.ToolStrip.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativewindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativewindow.WndProc(Message& m)
   at System.Windows.Forms.Nativewindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Any suggestions, or comments about the "dictionary" process that seems to an issue here, would be appreciated.

Larry

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Do you have a property descriptor defined for the property ses_date (or whichever) that you are trying to ensure the column exists for?  I am trying to understand your BO code and the little snippet of the error could come from more than one place, technically.
Larry Tucker
Larry Tucker
StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)
Group: StrataFrame Users
Posts: 69, Visits: 308
Trent L. Taylor (07/02/2008)
Do you have a property descriptor defined for the property ses_date (or whichever) that you are trying to ensure the column exists for?  I am trying to understand your BO code and the little snippet of the error could come from more than one place, technically.

Here is the ClaimBO code for the property descriptor"

''' <summary>

''' This provides a property descriptor that is used for reflection. If you have more than

''' one custom property, then create another entry in the array that is being returned.

''' </summary>

''' <returns></returns>

''' <remarks></remarks>

Protected Overrides Function GetCustomBindablePropertyDescriptors() As MicroFour.StrataFrame.Business.FieldPropertyDescriptor()

Return New FieldPropertyDescriptor() {New ReflectionPropertyDescriptor("ses_Date", Me.GetType())}

End Function

Thanks,

Larry

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
The problem is that this was a date field and the framework was looking to see if the value was a SmalLDateTime as this is treated differently when initializting the row.  We have made a change to the framework so that this will not produce an error in the future.  I will try and post a new beta build later in the day.
Larry Tucker
Larry Tucker
StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)StrataFrame User (139 reputation)
Group: StrataFrame Users
Posts: 69, Visits: 308
Trent,

Thanks for investigating and finding the glitch.  There is no hurry from my perspective as I just picked this field at random to test the general procedure for filling custom properties in one server pass.  I'll continue my testing with a text field and press on.

Larry

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