﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » StrataFrame Application Framework - V1 » WinForms (How do I?)  » How Do I Handle Foreign Keys Through List Controls?</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Tue, 09 Jun 2026 18:04:47 GMT</lastBuildDate><ttl>20</ttl><item><title>How Do I Handle Foreign Keys Through List Controls?</title><link>http://forum.strataframe.net/FindPost3604.aspx</link><description>This has got to be really simple, as I have been doing this throughout my coding years, but I can't make it happen using SF.&lt;br&gt;
&lt;br&gt;
I have an Organization BO, a Group BO, and a GroupOrganization BO. An Organization can belong to many groups and a Group can have many organizations. I want to use the GroupOrganization BO to handle this. (The GroupOrganization table just has two fields -- GroupId, and OrganizationId which are foreign keys referencing the primary keys in the respective tables).&lt;br&gt;
&lt;br&gt;
On the GroupOrganization BO, I just want to have a list control displaying all available Organizations, and one more list control displaying all available Groups. I want to be able to choose a Group, then choose (multiple) Organizations and click 'Save', resulting in proper records which look like (GroupId, OrganizationId) where both of these are composite primary keys.&lt;br&gt;
&lt;br&gt;
I need some guidance how to go about achieving this through SF.&lt;br&gt;
&lt;br&gt;
Thanks, and let me know if I can be more descriptive.</description><pubDate>Tue, 24 Oct 2006 07:53:59 GMT</pubDate><dc:creator>John Kujur</dc:creator></item><item><title>RE: How Do I Handle Foreign Keys Through List Controls?</title><link>http://forum.strataframe.net/FindPost3830.aspx</link><description>[quote]I was just curious about whether other SF users should also have these new DLLs? Is this going into an update/release?[/quote]&lt;/P&gt;&lt;P&gt;Only a few.&amp;nbsp; These DLLs contain the changes that will be released on Friday.&amp;nbsp; But it is stable as we are using this ourselves and anyone that is having specific problems we are letting have these DLLs.</description><pubDate>Tue, 24 Oct 2006 07:53:59 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: How Do I Handle Foreign Keys Through List Controls?</title><link>http://forum.strataframe.net/FindPost3828.aspx</link><description>Thanks Trent, Ben And Team.&lt;br&gt;
&lt;br&gt;
Yes My PKs are TinyInts as the number of records will never cross two digits here; and I have them auto-incrementing as it is a simple solution. It is just a little application I'm doing to test out SF. So yes, since these are converted into Bytes it all makes sense now.&lt;br&gt;
&lt;br&gt;
I haven't gone through the example yet, I'll be doing that now and will let you know.&lt;br&gt;
&lt;br&gt;
I was just curious about whether other SF users should also have these new DLLs? Is this going into an update/release?&lt;br&gt;
&lt;br&gt;
Thanks Again.</description><pubDate>Tue, 24 Oct 2006 00:53:33 GMT</pubDate><dc:creator>John Kujur</dc:creator></item><item><title>RE: How Do I Handle Foreign Keys Through List Controls?</title><link>http://forum.strataframe.net/FindPost3796.aspx</link><description>John,&lt;P&gt;Attached are two things....some updated StrataFrame DLLs and a Link Manager sample.&amp;nbsp; I ran into the problem you were encountering and I will explain it is just a minute.&amp;nbsp; First let me explain how to update your DLLs:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Updating SF DLLs:&lt;/STRONG&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Extract the SF DLLs to a temp folder&lt;/LI&gt;&lt;LI&gt;Drag the DLLs into the c:\windows\assembly folder (GAC)&lt;/LI&gt;&lt;LI&gt;Copy those same files to C:\Program Files\Common Files\MicroFour\StrataFrame&lt;/LI&gt;&lt;LI&gt;Restart all Visual Studio Instances&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;This will update your SF DLLs.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;The Problem&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Your entire problem surrounds the TinyInt as your primary key.&amp;nbsp; Your PKs were also autoincrementing which caused some additional side-effects.&amp;nbsp; A TinyInt is converted to a Byte in .NET (you can find this in the SQL Server Books Online).&amp;nbsp; The problem with this is that when a PK is auto-incrementing the framework will us negative numbers until the record is committed...obviously this won't work with a Byte since you cannot go below zero.&amp;nbsp; There was an additional problem that we found while testing your scenario that is the reason we gave you the new DLLs.&amp;nbsp; It has to do with a new record being added through a grid when there are already records populated within the Link Table in the BusinessLayerLinkManager while using TinyInt PKs.&amp;nbsp; This issue has been resolved with these DLLs.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;The Solution&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;You will notice that the business objects within the sample attached here have an alternate value returned on NULL.&amp;nbsp; Since the framework cannot create the negative PK place holders for a TinyInt and DbNull value is returned which will cause a number of errors.&amp;nbsp; To get around this, we set a Return Alternate Value on Null setting on each of the PKs to zero.&amp;nbsp; See the customized field property value through the BO Mapper below:&lt;/P&gt;&lt;P&gt;&lt;IMG src="http://forum.strataframe.net/Uploads/Images/c143cf65-aee0-4258-a932-4934.jpg"&gt;&lt;BR&gt;&lt;STRONG&gt;Note: &lt;/STRONG&gt;This needs to be done on each of the TinyInt PKs.&lt;/P&gt;&lt;P&gt;Since your PKs aure auto-incrementing, they will properly return the new PK once saved, but this just prevents the DbNull error from happening (since the PK could not be set to a negative value).&lt;/P&gt;&lt;P&gt;Past that I think the sample is pretty self-explanitory.&amp;nbsp; Let me know if you have any other questions regarding this.</description><pubDate>Mon, 23 Oct 2006 10:06:10 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: How Do I Handle Foreign Keys Through List Controls?</title><link>http://forum.strataframe.net/FindPost3789.aspx</link><description>I will check this out....just curious, I noticed that your primary keys are TinyInt's...so I assume that you will never have more than 250 records in this table or recreate a record 250 times?</description><pubDate>Mon, 23 Oct 2006 08:39:52 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: How Do I Handle Foreign Keys Through List Controls?</title><link>http://forum.strataframe.net/FindPost3782.aspx</link><description>Thanks, I'm attaching the package file.</description><pubDate>Mon, 23 Oct 2006 00:23:30 GMT</pubDate><dc:creator>John Kujur</dc:creator></item><item><title>RE: How Do I Handle Foreign Keys Through List Controls?</title><link>http://forum.strataframe.net/FindPost3750.aspx</link><description>John,&lt;/P&gt;&lt;P&gt;Send us the structure of these 3 tables and I will create you a sample for this exact scenario.&amp;nbsp; The easiest way is to use the DDT (Database Deployment Toolkit) to create the structures cause all you will need to send us is the package file that gets created.&amp;nbsp; But any other method will work also.&amp;nbsp; You can even give us an MDF and we will just mount the database if that is the easiest.&lt;/P&gt;&lt;P&gt;I thought this would be easier than going back and forth and it will not take long to create you this sample.</description><pubDate>Sat, 21 Oct 2006 09:50:55 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: How Do I Handle Foreign Keys Through List Controls?</title><link>http://forum.strataframe.net/FindPost3748.aspx</link><description>Can someone point me in the right direction please? Maybe some kind of sample or documentation?&lt;br&gt;
&lt;br&gt;
Thanks.</description><pubDate>Sat, 21 Oct 2006 06:03:13 GMT</pubDate><dc:creator>John Kujur</dc:creator></item><item><title>RE: How Do I Handle Foreign Keys Through List Controls?</title><link>http://forum.strataframe.net/FindPost3656.aspx</link><description>Thanks for the tips.&lt;/P&gt;&lt;P&gt;Here's what I did:&lt;/P&gt;&lt;P&gt;1. I made the GroupOrganizationBO the PrimaryBusinessObject on an SF Maintenance Form.&lt;BR&gt;2. I added&amp;nbsp;a GroupBO and an OrganizationBO to the form.&lt;BR&gt;3. I called a "FillAll" method for all three BOs in their respective ParentFormLoading events.&lt;BR&gt;4. I dropped a combobox and set its BusinessObject to GroupOrganizationBO and its bindingField to GroupId. I set this to populate through GroupBO1 on formload.&lt;BR&gt;5. I dropped another combobox and set its BusinessObject to GroupOrganizationBO and its bindingField to OrganizationId. I set this to populate through OrganizationBO1 on formload.&lt;BR&gt;6. I dropped a BusinessLayerLinkManager and set its Table1 to GroupBO1, Table2 to OrganizationBO1, TableLink to GroupOrganizationBO1, as well as proper values for ForeignKeyToTable1, ForeignKeyToTable2, PrimaryKeyOnTable1, and PrimaryKeyOnTable2.&lt;/P&gt;&lt;P&gt;I get the following exception in Visual Studio when I run this:&lt;BR&gt;-------------------------------------------------------------------------------&lt;BR&gt;MicroFour.StrataFrame.Business.BusinessLayerException was unhandled by user code&lt;BR&gt;&amp;nbsp; Message="The CurrentRow could not be evaluated because the CurrentRowIndex is out of range.&amp;nbsp; Business object record count: 0.&amp;nbsp; CurrentRowIndex: -1."&lt;BR&gt;&amp;nbsp; Source="MicroFour StrataFrame Business"&lt;BR&gt;&amp;nbsp; StackTrace:&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; at MicroFour.StrataFrame.Business.BusinessLayer.get_CurrentRow()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; at SalaryCSSF2.GroupOrganizationBO.get_GroupId() in D:\SalaryCSSF2\SalaryCSSF2\BusinessObjects\GroupOrganizationBO.Designer.vb:line 239&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; at SalaryCSSF2.GroupOrganizationBO.Field_GroupId_Descriptor.GetValue(Object component) in D:\SalaryCSSF2\SalaryCSSF2\BusinessObjects\GroupOrganizationBO.Designer.vb:line 598&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; at MicroFour.StrataFrame.Business.BusinessLayerLinkManager.HandleTableLinkNavigated(NavigatedEventArgs e)&lt;BR&gt;------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;When I go along with the exceptions, I can see the form. On clicking the "New" button, I get an error (pls see attached image).&lt;/P&gt;&lt;P&gt;Could you please let me know whether the steps I am following are okay? I have three or four records in both Group and Organization tables, so I don't really know why I'm getting the CurrentRowIndex = -1 message.&lt;/P&gt;&lt;P&gt;Are there two separate issues here?&lt;/P&gt;&lt;P&gt;Thanks.</description><pubDate>Tue, 17 Oct 2006 08:47:57 GMT</pubDate><dc:creator>John Kujur</dc:creator></item><item><title>RE: How Do I Handle Foreign Keys Through List Controls?</title><link>http://forum.strataframe.net/FindPost3611.aspx</link><description>No more description needed :)&lt;/P&gt;&lt;P&gt;This is accomplished using the BusinessLayerLinkManager.&amp;nbsp; Essentially, you drop a BusinessLayerLinkManager on the form and set the Table1, Table2, and TableLink properties.&amp;nbsp; Then on the BLLM, you set the primary key and foreign key fields on the appropriate properties and it will manage the link for you.&amp;nbsp; When you add a new record to the link table, it will retrieve the primary key values from the two outside business objects and maintain the relationships between them. &lt;/P&gt;&lt;P&gt;As for a control, we have a CheckedTreeView control that you can use or you can use a CheckedListBox control.&amp;nbsp; Either way, in the CheckedChanged event (NodeStateChanged in the CheckedTreeView), you will need to just add or delete the record from the link table.&amp;nbsp; Call Save() when you're done and that's it.</description><pubDate>Mon, 16 Oct 2006 08:25:40 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item></channel></rss>