﻿<?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 » Business Objects and Data Access (How do I?)  » Custom field with storage</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Wed, 09 Sep 2026 06:18:44 GMT</lastBuildDate><ttl>20</ttl><item><title>Custom field with storage</title><link>http://forum.strataframe.net/FindPost9620.aspx</link><description>Hi,&lt;br&gt;
Anyway I can create custom BO field that able to store value without using sql server view?&lt;br&gt;
&lt;br&gt;
Thank you</description><pubDate>Mon, 18 Jun 2007 08:56:06 GMT</pubDate><dc:creator>Chan</dc:creator></item><item><title>RE: Custom field with storage</title><link>http://forum.strataframe.net/FindPost9641.aspx</link><description>Unfortunately, there's no way to prevent the get {} from firing while refreshing.&amp;nbsp; .NET's data binding works in such a way that if any bound property on a data source raises its xChanged event, all controls bound to the same context refresh as well.&amp;nbsp; So, if any control's data changes, all bound controls will refresh.&lt;/P&gt;&lt;P&gt;My recommendation would be to add an "initialized" flag to your business object and only retrieve the value if the field has not been initialized.&amp;nbsp; Something like this:&lt;/P&gt;&lt;P&gt;private bool _propInitialized = false;&lt;BR&gt;private string _customPropField;&lt;BR&gt;public string MyCustomProp&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; get&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (!this._propInitialized)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this._customPropField = this.GetCustomProp();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this._propInitialized = true;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;}</description><pubDate>Mon, 18 Jun 2007 08:56:06 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item><item><title>RE: Custom field with storage</title><link>http://forum.strataframe.net/FindPost9630.aspx</link><description>Hi,&lt;br&gt;
Thank you for reply.&lt;br&gt;
Currently, i am using as you mentioned to retrieve custom field value. I found that, this property Get{} event always fired while refreshing. I am looking for anyway to prevent overload.&lt;br&gt;
&lt;br&gt;
Any ideas?&lt;br&gt;
&lt;br&gt;
Thank you</description><pubDate>Sat, 16 Jun 2007 01:38:20 GMT</pubDate><dc:creator>Chan</dc:creator></item><item><title>RE: Custom field with storage</title><link>http://forum.strataframe.net/FindPost9622.aspx</link><description>Chan,&lt;br&gt;
&lt;br&gt;
If I understand you, you are asking if you can store something to the database, but not using the underlying DataTable that the BO uses within a custom property. If this is what you mean...&lt;br&gt;
&lt;br&gt;
I've done this many times. In the set statement of the property, just use the ExecuteNonQuery() of the BO to execute any command on db that is needed.  In the get statement of the property, use ExecuteScalar() (most likely) to get the value. &lt;br&gt;
&lt;br&gt;
Here's a quick example (in VB):&lt;br&gt;
&lt;br&gt;
[codesnippet]Public Property ValueNotInBO() As String&lt;br&gt;
  Get&lt;br&gt;
    ' if no data is returned from the db, return an empty string&lt;br&gt;
    Dim value As String = String.Empty&lt;br&gt;
    Using cmd As New SqlCommand()&lt;br&gt;
       ' Here I'm assuming the PK of the BO, called bo_pk, is also the pk of TableNotUsedByBO &lt;br&gt;
       cmd.CommandText = "Select ValueNotInBO From TableNotUsedByBO Where pk = @pk"&lt;br&gt;
       cmd.Parameters.Add("@pk",Int)&lt;br&gt;
       cmd.Parameters("@pk").Value = Me.bo_pk&lt;br&gt;
       ' It is possible that there is no match, in which case ret will be nothing&lt;br&gt;
       ' It might also be possible that ret is NULL (based on db schema)&lt;br&gt;
       Dim ret As Object = Me.ExecuteScalar(cmd)&lt;br&gt;
       If ret IsNot Nothing AndAlso ret IsNot DBNull.Value Then&lt;br&gt;
         value = CType(ret,String)&lt;br&gt;
       End If&lt;br&gt;
    End Using&lt;br&gt;
  End Get&lt;br&gt;
  Set(value As String)&lt;br&gt;
     ' In real code, you'd have to check if an insert or update was needed&lt;br&gt;
     ' Here I'm just doing the insert.&lt;br&gt;
     Using cmd As New SqlCommand()&lt;br&gt;
       cmd.CommandText = "Insert Into TableNotUsedByBO (pk,ValueNotInBO) Value (@pk,@value)"&lt;br&gt;
       ' Here I'm assuming the PK of the BO, called bo_pk, is also the pk of TableNotUsedByBO &lt;br&gt;
       cmd.Parameters.Add("@value",Int)&lt;br&gt;
       cmd.Parameters("@value").Value = value&lt;br&gt;
       cmd.Parameters.Add("@pk",Int)&lt;br&gt;
       cmd.Parameters("@pk").Value = Me.bo_pk&lt;br&gt;
       Dim ret As Object = Me.ExecuteScalar(cmd)&lt;br&gt;
       If ret IsNot Nothing AndAlso ret IsNot DBNull.Value Then&lt;br&gt;
         value = CType(ret,String)&lt;br&gt;
       End If&lt;br&gt;
    End Using&lt;br&gt;
 End Set&lt;br&gt;
End Property[/codesnippet]&lt;br&gt;
&lt;br&gt;
Hope this helps!</description><pubDate>Fri, 15 Jun 2007 13:31:48 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item></channel></rss>