<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="RSS_xslt_style.asp" version="1.0" ?>
<rss version="2.0" xmlns:WebWizForums="http://syndication.webwiz.co.uk/rss_namespace/">
 <channel>
  <title>DevForce Community Forum : When to initialize an Entity after Load</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : DevForce 2009 : When to initialize an Entity after Load</description>
  <pubDate>Mon, 27 Apr 2026 08:31:53 -700</pubDate>
  <lastBuildDate>Tue, 22 Feb 2011 11:46:15 -700</lastBuildDate>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Web Wiz Forums 9.69</generator>
  <ttl>360</ttl>
  <WebWizForums:feedURL>www.ideablade.com/forum/RSS_post_feed.asp?TID=1469</WebWizForums:feedURL>
  <image>
   <title>DevForce Community Forum</title>
   <url>http://www.ideablade.com/forum/forum_images/IdeaBlade_logo_tm.png</url>
   <link>http://www.ideablade.com/forum/</link>
  </image>
  <item>
   <title>When to initialize an Entity after Load :  I ran into a similar scenario...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1469&amp;PID=10029#10029</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1079" rel="nofollow">patsissons</a><br /><strong>Subject:</strong> 1469<br /><strong>Posted:</strong> 22-Feb-2011 at 11:46am<br /><br /><div style=": rgb255, 255, 255; margin-left: 1px; margin-top: 1px; margin-right: 1px; margin-bottom: 1px; color: rgb0, 0, 0; font-weight: normal; font-size: 12px; line-height: 1.4; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; -: n&#111;ne; ">I ran into a similar scenario where i need to do some post-load initialization. &nbsp;My approach was the following:<div style="font-family: Verdana, Arial, Helvetica, sans-serif; "><br></div><div><font ="apple-style-span"="" face="'Courier New', Courier, mono">public partial class MyEntity</font></div><div><font ="apple-style-span"="" face="'Courier New', Courier, mono">{</font></div><div><font ="apple-style-span"="" face="'Courier New', Courier, mono">&nbsp;&nbsp; &nbsp;private bool m_Initialized = false;</font></div><div><font ="apple-style-span"="" face="'Courier New', Courier, mono"><br></font></div><div><font ="apple-style-span"="" face="'Courier New', Courier, mono">&nbsp;&nbsp; &nbsp;protected override&nbsp;</font><span ="Apple-style-span" style="font-family: 'Courier New', Courier, mono; ">void</span><span ="Apple-style-span" style="font-family: 'Courier New', Courier, mono; ">&nbsp;OnPropertyChanged(PropertyChangedEventArgs e)</span></div><div><font ="apple-style-span"="" face="'Courier New', Courier, mono">&nbsp;&nbsp; &nbsp;{</font></div><div><font ="apple-style-span"="" face="'Courier New', Courier, mono">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;base.OnPropertyChanged(e);</font></div><div><font ="apple-style-span"="" face="'Courier New', Courier, mono">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if (m_Initialized == false)</font></div><div><font ="apple-style-span"="" face="'Courier New', Courier, mono">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;{</font></div><div><font ="apple-style-span"="" face="'Courier New', Courier, mono">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Initialize();</font></div><div><font ="apple-style-span"="" face="'Courier New', Courier, mono">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;m_Initialized = true;</font></div><div><font ="apple-style-span"="" face="'Courier New', Courier, mono">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}</font></div><div><font ="apple-style-span"="" face="'Courier New', Courier, mono">&nbsp;&nbsp; &nbsp;}</font></div><div><font ="apple-style-span"="" face="'Courier New', Courier, mono"><br></font></div><div><font ="apple-style-span"="" face="'Courier New', Courier, mono">&nbsp;&nbsp; &nbsp;private void Initialize()</font></div><div><font ="apple-style-span"="" face="'Courier New', Courier, mono">&nbsp;&nbsp; &nbsp;{</font></div><div><font ="apple-style-span"="" face="'Courier New', Courier, mono">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;// Do whatever in here.</font></div><div><font ="apple-style-span"="" face="'Courier New', Courier, mono">&nbsp;&nbsp; &nbsp;}</font></div><div><font ="apple-style-span"="" face="'Courier New', Courier, mono">}</font></div><div style="font-family: Verdana, Arial, Helvetica, sans-serif; "><br></div><div style="font-family: Verdana, Arial, Helvetica, sans-serif; ">Because the entity framework will fire a property changed event (with e.propertyName == null) as soon as the entity is loaded, you can basically use this to inject your own init code into the entity life cycle. &nbsp;This is certainly far from an optimal solution, but it works, it is relatively simple, and it is reasonably efficient.</div><div style="font-family: Verdana, Arial, Helvetica, sans-serif; "><br></div><div style="font-family: Verdana, Arial, Helvetica, sans-serif; ">I ended up using this approach to initialize collection change handlers for a collection nav prop that existed on a specific type of entity. &nbsp;The collection change event needed to be handled by every entity of that type that was loaded from the db.</div></div><span style="font-size:10px"><br /><br />Edited by patsissons - 22-Feb-2011 at 11:48am</span>]]>
   </description>
   <pubDate>Tue, 22 Feb 2011 11:46:15 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1469&amp;PID=10029#10029</guid>
  </item> 
  <item>
   <title>When to initialize an Entity after Load : I was able to use a combination...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1469&amp;PID=5991#5991</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=543" rel="nofollow">pk55</a><br /><strong>Subject:</strong> 1469<br /><strong>Posted:</strong> 27-Dec-2009 at 5:36pm<br /><br /><P>I was able to use a combination of the EntityGroup EntityChanged and EntityPropertyChanged events to do what I need (setting computed non-persisted properties for example) so this is no longer a priority for us.</P>]]>
   </description>
   <pubDate>Sun, 27 Dec 2009 17:36:47 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1469&amp;PID=5991#5991</guid>
  </item> 
  <item>
   <title>When to initialize an Entity after Load : Our next release is not until...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1469&amp;PID=5970#5970</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=11" rel="nofollow">kimj</a><br /><strong>Subject:</strong> 1469<br /><strong>Posted:</strong> 22-Dec-2009 at 8:51am<br /><br />Our next release is not until March, and we don't currently have this feature scheduled for it.&nbsp;&nbsp; Please let us know if this is an important feature for you (and maybe also tell us about your use case).]]>
   </description>
   <pubDate>Tue, 22 Dec 2009 08:51:13 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1469&amp;PID=5970#5970</guid>
  </item> 
  <item>
   <title>When to initialize an Entity after Load : I see this still hasn&amp;#039;t been...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1469&amp;PID=5957#5957</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=543" rel="nofollow">pk55</a><br /><strong>Subject:</strong> 1469<br /><strong>Posted:</strong> 18-Dec-2009 at 3:32pm<br /><br />I see this still hasn't been addressed in the Dec 14th release (based on what I can tell from the Release Notes).&nbsp; Are there any updates about when or if this will be addressed?]]>
   </description>
   <pubDate>Fri, 18 Dec 2009 15:32:24 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1469&amp;PID=5957#5957</guid>
  </item> 
  <item>
   <title>When to initialize an Entity after Load : Sorry we have not yet addressed...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1469&amp;PID=5622#5622</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=11" rel="nofollow">kimj</a><br /><strong>Subject:</strong> 1469<br /><strong>Posted:</strong> 14-Oct-2009 at 8:54am<br /><br />Sorry we have not yet addressed this -- as I said in an earlier post it's something (i.e., a feature) we will look into.&nbsp; Right now&nbsp;the EntityChanging/EntityChanged events are probably the best option if you need to perform special logic for newly loaded entities.<DIV>&nbsp;</DIV><DIV>I should add too that&nbsp;property interceptors should not be added on an entity instance basis, they should be added for an entity type.&nbsp;&nbsp; If InitLastNameInterceptor is adding interceptor action(s) then it should instead be called once only for the Person entity type, not repeatedly for every person instance.</DIV><DIV>&nbsp;</DIV><DIV>And just to be clear on these events, the Fetching and Fetched events fire on the EntityManager, so need to be initialized only once per EntityManager.&nbsp; The EntityChanging and EntityChanged events fire on a specific EntityGroup, e.g. the Person EntityGroup, so these events should be initialized only once for that group.</DIV>]]>
   </description>
   <pubDate>Wed, 14 Oct 2009 08:54:32 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1469&amp;PID=5622#5622</guid>
  </item> 
  <item>
   <title>When to initialize an Entity after Load : Bump </title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1469&amp;PID=5621#5621</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=472" rel="nofollow">Sinnema</a><br /><strong>Subject:</strong> 1469<br /><strong>Posted:</strong> 14-Oct-2009 at 5:00am<br /><br />Bump]]>
   </description>
   <pubDate>Wed, 14 Oct 2009 05:00:34 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1469&amp;PID=5621#5621</guid>
  </item> 
  <item>
   <title>When to initialize an Entity after Load : Hi Gaby  Thanks for the reply....</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1469&amp;PID=5422#5422</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=472" rel="nofollow">Sinnema</a><br /><strong>Subject:</strong> 1469<br /><strong>Posted:</strong> 17-Sep-2009 at 11:18pm<br /><br />Hi&nbsp; Gaby<DIV>&nbsp;</DIV><DIV>Thanks for the reply. I guess you didn't read the post correctly. I didn't ask a question about the Create, we've got that topic covered correctly. I was asking a question about the Load of an existing entity in the DB.</DIV><DIV>&nbsp;</DIV><DIV>Thanks for the code anyway. I've learned something new from it.</DIV><DIV>&nbsp;</DIV><DIV>Regards,</DIV><DIV>Paul Sinnema</DIV><DIV>Diartis AG</DIV>]]>
   </description>
   <pubDate>Thu, 17 Sep 2009 23:18:09 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1469&amp;PID=5422#5422</guid>
  </item> 
  <item>
   <title>When to initialize an Entity after Load : Since there is so much going on...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1469&amp;PID=5417#5417</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=308" rel="nofollow">skingaby</a><br /><strong>Subject:</strong> 1469<br /><strong>Posted:</strong> 17-Sep-2009 at 8:01pm<br /><br />Since there is so much going on in the construction / serialization / fetching of entities.  We do not use the constructor for post-init.  Instead, we have followed the pattern shown in the Prism Explorer sample where a static Create method is added to the entity class.  This Create method calls the constructor and then performs init work like setting the Parent entity and initializing defaults.  <br /><br />For example:<br /><br />This is the base Create method in the BaseEntity class (upon which most of our Entities are based):<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #region Create<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; protected static BaseEntity Create&lt;T&gt;(User user) where T : BaseEntity<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;InitManager();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;T item = Manager.CreateEntity&lt;T&gt;();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GetATemporaryKey(item);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;item.InitializeDefaults(user);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AddToManager(item);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;item.InitializeChildren(user);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return item;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; protected static void GetATemporaryKey&lt;T&gt;(T item) where T : Entity<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (Manager == null)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  InitManager();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var key = item.EntityAspect.EntityMetadata.KeyProperties&#091;0&#093;;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (key.IsAutoIncrementing)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  try<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Manager.GenerateId(item, key);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  catch (IdeaBlade.Core.IdeaBladeException)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//eat the exception thrown if this class does not have a Generator<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  catch (Exception)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; protected static void AddToManager(Entity entity)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;entity.EntityAspect.AddToManager();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; protected virtual void InitializeDefaults(User user) { }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; protected virtual void InitializeChildren(User user) { }<br /><br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #endregion<br /><br />The Entity then has a Create method that looks like this, with whatever parameters needed being passed in:<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #region Create<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static Deal Create(User user)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return (Deal)Create&lt;Deal&gt;(user);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; protected override void InitializeDefaults(User user)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.EnteredBy = user.UserId;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.DateEntered = DateTime.Now;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.DateOfDeal = DateTime.Today;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.FlowDateStart = DateTime.Today.AddDays(1);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.FlowDateEnd = DateTime.Today.AddWeekdays(1);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; protected override void InitializeChildren(User user)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AddDealPricing(user);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #endregion<br /><br />The Create method in the DealPricing (a child class) looks like this:<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #region Create<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static DealPricing Create(Deal deal, User user)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var dp = (DealPricing)Create&lt;DealPricing&gt;(user);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dp.Deal = deal;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return dp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; protected override void InitializeDefaults(User user)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.EnteredBy = user.UserId;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #endregion<br /><br />Maybe this will help?  Let me know what you think.]]>
   </description>
   <pubDate>Thu, 17 Sep 2009 20:01:05 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1469&amp;PID=5417#5417</guid>
  </item> 
  <item>
   <title>When to initialize an Entity after Load : EntityChanging / EntityChanged...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1469&amp;PID=5387#5387</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=11" rel="nofollow">kimj</a><br /><strong>Subject:</strong> 1469<br /><strong>Posted:</strong> 15-Sep-2009 at 8:36am<br /><br />EntityChanging / EntityChanged events fire a little less often, and in a more controlled manner, than the entity constructor is called.&nbsp; The EntityGroup holds all entities of a given type, and these events fire when entities are added (for various reasons), removed or modified.&nbsp; The Action and Entity properties of the EntityChangedEventArgs provided to the handler will tell you the specifics of why the event fired.<DIV>&nbsp;</DIV><DIV>We're looking at providing a better means of (post)-construction interception.</DIV>]]>
   </description>
   <pubDate>Tue, 15 Sep 2009 08:36:03 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1469&amp;PID=5387#5387</guid>
  </item> 
  <item>
   <title>When to initialize an Entity after Load : Hi Kim,  Thanks for the reply....</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1469&amp;PID=5383#5383</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=472" rel="nofollow">Sinnema</a><br /><strong>Subject:</strong> 1469<br /><strong>Posted:</strong> 14-Sep-2009 at 11:22pm<br /><br /><DIV>Hi Kim,</DIV><DIV>&nbsp;</DIV><DIV>Thanks for the reply. Aha, the EntityChanged event on the EntityGroup. Wouldn't have thought of that very soon. I guess we get events for all Entities changing in the group so this is going to be a work-around at best.</DIV><DIV>&nbsp;</DIV><DIV>We realy find it hard to believe that these kind of interception points aren't available yet. We absolutely believe extending DevForce with these (post-)construction events is a must.</DIV><DIV>&nbsp;</DIV><DIV>Regards,</DIV><DIV>Paul Sinnema</DIV><DIV>Diartis AG</DIV>]]>
   </description>
   <pubDate>Mon, 14 Sep 2009 23:22:22 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1469&amp;PID=5383#5383</guid>
  </item> 
  <item>
   <title>When to initialize an Entity after Load : The entity constructor is too...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1469&amp;PID=5379#5379</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=11" rel="nofollow">kimj</a><br /><strong>Subject:</strong> 1469<br /><strong>Posted:</strong> 14-Sep-2009 at 2:08pm<br /><br />The entity constructor is too early for just about anything - at construction the entity is not yet attached to an EntityManager and most (if not all) of its "entity aspect" type of features will not be present.&nbsp; The constructor is also invoked both for a wholly new item, as fetched items are loaded, and during de-serialization when the item is moved between tiers.<DIV>&nbsp;</DIV><DIV>At present, probably the best place for you to add initialization logic is via the EntityChanged event on the containing EntityGroup.&nbsp; An action is passed with the arguments to help determine what is happening with the entity.&nbsp; So something like this would be better:</DIV><DIV>&nbsp;</DIV><DIV><table width="99%"><tr><td><pre class="BBcode"></DIV><DIV><FONT size=2>_entityManager.GetEntityGroup(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>typeof</FONT></FONT><FONT size=2>(</FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>Person</FONT></FONT><FONT size=2>)).EntityChanged += (o, e) =&gt; {</FONT></DIV><DIV><FONT color=#0000ff size=2><FONT color=#0000ff size=2>&nbsp;&nbsp; if</FONT></FONT><FONT size=2> (e.Action == </FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>EntityAction</FONT></FONT><FONT size=2>.AddOnQuery) {</FONT></DIV><DIV><FONT size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Init for the entity instance ...</FONT></DIV><DIV><FONT size=2>&nbsp; &nbsp;}</FONT></DIV><DIV><FONT size=2>};</FONT></DIV><DIV><FONT size=2></pre></td></tr></table></FONT></DIV><DIV><FONT size=2></FONT>&nbsp;</DIV><DIV><FONT size=2>We've had other requests for construction / post-construction interception points so we may do something to make this easier in a future release.</FONT></DIV><DIV><FONT size=2></FONT>&nbsp;</DIV><DIV><FONT size=2>There are a couple of other things to watch out for too -</FONT></DIV><DIV><FONT size=2>1) You probably don't want to call AddToManager from the constructor, since the parameterless constructor can be called in situations where you might not expect.</FONT></DIV><DIV><FONT size=2>2) <strong>You definitely don't want to add a Fetched event handler for every single entity</strong>.&nbsp; The Fetched event is defined on the EntityManager and will fire for any queries made on the EM that will be sent to the data source.&nbsp; Setting a handler up for each constructed entity means your handler will be called </FONT><FONT size=2>many more times than needed.</FONT></DIV><DIV><FONT size=2>&nbsp;</DIV></FONT>]]>
   </description>
   <pubDate>Mon, 14 Sep 2009 14:08:33 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1469&amp;PID=5379#5379</guid>
  </item> 
  <item>
   <title>When to initialize an Entity after Load : It would be nice if someone would...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1469&amp;PID=5378#5378</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=472" rel="nofollow">Sinnema</a><br /><strong>Subject:</strong> 1469<br /><strong>Posted:</strong> 14-Sep-2009 at 1:21pm<br /><br /><P>It would be nice if someone would give us a hint today. The time-shift always poses a problem for us Europeans ;-)</P><DIV></DIV>]]>
   </description>
   <pubDate>Mon, 14 Sep 2009 13:21:21 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1469&amp;PID=5378#5378</guid>
  </item> 
  <item>
   <title>When to initialize an Entity after Load : Hi, We would like to initialize...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1469&amp;PID=5373#5373</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=472" rel="nofollow">Sinnema</a><br /><strong>Subject:</strong> 1469<br /><strong>Posted:</strong> 14-Sep-2009 at 8:33am<br /><br /><P>Hi,</P><DIV>We would like to initialize some properties in the Entity after it has been Fetched from the DB. We've tried it in the Constructor but that seems to be too early. We've even tried the code below. This construction was looping indefenitly when we don't unregister the Fetched event.</DIV><DIV>&nbsp;</DIV><DIV>We've already spent 4 hours trying to solve this ourselves but we can't seem to find the right answer. Please help us.</DIV><DIV>&nbsp;</DIV><DIV>Regards,</DIV><DIV>Paul Sinnema</DIV><DIV>Diartis AG</DIV><DIV>&nbsp;</DIV><DIV>&nbsp; // Constructor for Person</DIV><DIV>&nbsp;&nbsp;public Person()<BR>&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;InitEntity(InitEntityCommand.Load);<BR>&nbsp;&nbsp;&nbsp;&nbsp; }<BR></DIV><DIV>&nbsp;&nbsp;public override void InitEntity(InitEntityCommand initEntityCommand)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;base.InitEntity(initEntityCommand);</DIV><DIV>&nbsp;&nbsp;&nbsp;switch (initEntityCommand)<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;case InitEntityCommand.Load:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;EntityAspect.AddToManager();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;EntityAspect.EntityManager.Fetched += new EventHandler&lt;EntityFetchedEventArgs&gt;(EntityManagerFetched);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;</DIV><DIV>&nbsp;&nbsp;&nbsp;&nbsp;case InitEntityCommand.Create:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;InitLastNameInterceptor();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;</DIV><DIV>&nbsp;&nbsp;&nbsp;&nbsp;default:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;}</DIV><DIV>&nbsp;&nbsp;void EntityManagerFetched(object sender, EntityFetchedEventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;EntityAspect.EntityManager.Fetched -= new EventHandler&lt;EntityFetchedEventArgs&gt;(EntityManagerFetched);<BR>&nbsp;&nbsp;&nbsp;SetFullName();<BR>&nbsp;&nbsp;&nbsp;InitLastNameInterceptor();<BR>&nbsp;&nbsp;}</DIV><DIV>&nbsp;</DIV><span style="font-size:10px"><br /><br />Edited by Sinnema - 14-Sep-2009 at 8:34am</span>]]>
   </description>
   <pubDate>Mon, 14 Sep 2009 08:33:27 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1469&amp;PID=5373#5373</guid>
  </item> 
 </channel>
</rss>