<?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 : Computing Aggregate Values Efficiently with Dynamic Entities</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : DevForce Classic : Computing Aggregate Values Efficiently with Dynamic Entities</description>
  <pubDate>Fri, 12 Jun 2026 11:24:39 -700</pubDate>
  <lastBuildDate>Wed, 06 Jun 2007 12:54:20 -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=43</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>Computing Aggregate Values Efficiently with Dynamic Entities :  Answer: A sproc is certainly...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=43&amp;PID=108#108</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=21" rel="nofollow">IdeaBlade</a><br /><strong>Subject:</strong> 43<br /><strong>Posted:</strong> 06-Jun-2007 at 12:54pm<br /><br /><FONT face="Times New Roman" size=2><P =Questi&#111;n style="MARGIN: 0in 0in 0pt"><strong><EM><FONT size=3>Answer:</FONT></EM></strong></P><P =Ms&#111;normal style="MARGIN: 8pt 0in 0pt">A sproc is certainly the easy route, but a few words of caution. </P><P =Ms&#111;normal style="MARGIN: 8pt 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l1 level1 lfo1; tab-stops: list .5in"><SPAN style="mso-list: Ignore">(1)<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN>You probably want to make sure you call this with&nbsp;DataSourceOnly;</P><P =Ms&#111;normal style="MARGIN: 8pt 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l1 level1 lfo1; tab-stops: list .5in"><SPAN style="mso-list: Ignore">(2)<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN>You want to stick some kind of&nbsp;guard in the property so that it is invoked only once per ... microsecond? ... and cached&nbsp;in your business object otherwise; remember that .NET calls properties many times in a row for totally spurious reasons and you don't want to keep making trips to the database each time;</P><P =Ms&#111;normal style="MARGIN: 8pt 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l1 level1 lfo1; tab-stops: list .5in"><SPAN style="mso-list: Ignore">(3)<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN>The balance will be based on data in the database, not data in the client - which means there could be a serious disconnect between what the user sees on screen - what she adds up with her hand calculator&nbsp;- and the results returned from the property; if there&nbsp;is any chance of a discrepancy, you have to figure out how to deal with it. </P><P =Ms&#111;normal style="MARGIN: 8pt 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l1 level1 lfo1; tab-stops: list .5in"><SPAN style="mso-list: Ignore">(4)<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN>This approach assumes that the client is continuously connected to the database.</P><P =Ms&#111;normal style="MARGIN: 8pt 0in 0pt">For all of these reasons, I avoid aggregates unless I have a proven performance issue; and then I take steps to deal with the problems mentioned.</P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><SPAN style="COLOR: navy; FONT-FAMILY: Arial; mso-bidi-font-size: 10.0pt"><?:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p>&nbsp;</o:p></SPAN></P><P =Ms&#111;normal style="MARGIN: 8pt 0in 0pt">Another approach is to use dynamic entities.</P><P =Ms&#111;normal style="MARGIN: 8pt 0in 0pt">Dynamic entity types work great for the following reasons:</P><UL style="MARGIN-TOP: 0in" =disc><LI =Ms&#111;normal style="MARGIN: 8pt 0in 0pt; mso-list: l4 level1 lfo2; tab-stops: list .5in">You don’t know the structure of the class until runtime.<SPAN style="FONT-SIZE: 12pt"> </SPAN></LI><LI =Ms&#111;normal style="MARGIN: 8pt 0in 0pt; mso-list: l4 level1 lfo2; tab-stops: list .5in">You want to generate aggregate statistics from a table. You may not know which column is returned until runtime, e.g. the user picks which statistic to compute.<SPAN style="FONT-SIZE: 12pt"> </SPAN></LI><LI =Ms&#111;normal style="MARGIN: 8pt 0in 0pt; mso-list: l4 level1 lfo2; tab-stops: list .5in">You want to retrieve the minimum number of columns necessary to present the result in a grid. Again, you may not know which columns to retrieve until runtime based on user’s selection.<SPAN style="FONT-SIZE: 12pt"> </SPAN></LI></UL><P =Ms&#111;normal style="MARGIN: 8pt 0in 0pt">Once defined, dynamic entity type instances can be queried, created, modified, and deleted just like regular DevForce entities.</P><P =Ms&#111;normal style="MARGIN: 8pt 0in 0pt">In the example in the attachment, the Employee has a custom property called TotalOrderRevenue with computes the total revenue for the Employee’s orders. Key points are highlighted below.</P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt 0.25in"><SPAN style="COLOR: navy; FONT-FAMILY: Arial; mso-bidi-font-size: 10.0pt"><o:p>&nbsp;</o:p></SPAN></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt 0.25in"><SPAN style="COLOR: navy; FONT-FAMILY: Arial; mso-bidi-font-size: 10.0pt">&nbsp; In Employee.cs:<o:p></o:p></SPAN></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt 0.25in"><SPAN style="COLOR: navy; FONT-FAMILY: Arial; mso-bidi-font-size: 10.0pt"><o:p>&nbsp;</o:p></SPAN></P><P =CodeSnippet style="MARGIN: 0in 0in 0pt 0.25in"><FONT style=": #e6e6e6"><FONT face="Courier New"><strong><FONT color=#808080>&nbsp;&nbsp;&nbsp; ///</FONT><SPAN style="COLOR: green"> </SPAN><FONT color=#808080>&lt;summary&gt;</FONT></strong></FONT></FONT></P><P =CodeSnippet style="MARGIN: 0in 0in 0pt 0.25in"><FONT style=": #e6e6e6"><FONT face="Courier New"><strong><FONT color=#808080>&nbsp;&nbsp;&nbsp; ///</FONT><SPAN style="COLOR: green"> Total revenue for this Employee's orders<o:p></o:p></SPAN></strong></FONT></FONT></P><P =CodeSnippet style="MARGIN: 0in 0in 0pt 0.25in"><FONT style=": #e6e6e6"><FONT face="Courier New"><strong><FONT color=#808080>&nbsp;&nbsp;&nbsp; ///</FONT><SPAN style="COLOR: green"> </SPAN><FONT color=#808080>&lt;/summary&gt;</FONT></strong></FONT></FONT></P><P =CodeSnippet style="MARGIN: 0in 0in 0pt 0.25in"><FONT style=": #e6e6e6"><FONT face="Courier New"><strong><FONT color=#808080>&nbsp;&nbsp;&nbsp; </FONT><SPAN style="COLOR: blue">public</SPAN><FONT color=#808080> </FONT><SPAN style="COLOR: blue">double</SPAN><FONT color=#808080> TotalOrderRevenue {</FONT></strong></FONT></FONT></P><P =CodeSnippet style="MARGIN: 0in 0in 0pt 0.25in"><FONT style=": #e6e6e6"><FONT face="Courier New"><strong><FONT color=#808080>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT><SPAN style="COLOR: green">// Calculated property using a PassThruQuery and a dynamic entity type.<o:p></o:p></SPAN></strong></FONT></FONT></P><P =CodeSnippet style="MARGIN: 0in 0in 0pt 0.25in"><FONT style=": #e6e6e6"><FONT face="Courier New"><strong><FONT color=#808080>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT><SPAN style="COLOR: blue">get</SPAN><FONT color=#808080> {</FONT></strong></FONT></FONT></P><P =CodeSnippet style="MARGIN: 0in 0in 0pt 0.25in"><FONT style=": #e6e6e6"><FONT face="Courier New"><strong><FONT color=#808080>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT><SPAN style="COLOR: green">// Can use guard clause here to limit calculation.<o:p></o:p></SPAN></strong></FONT></FONT></P><P =CodeSnippet style="MARGIN: 0in 0in 0pt 0.25in"><FONT style=": #e6e6e6"><FONT face="Courier New"><strong><FONT color=#808080>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT><SPAN style="COLOR: green">// Example: Recalculate if 10 seconds has elapsed since last calculation.<o:p></o:p></SPAN></strong></FONT></FONT></P><P =CodeSnippet style="MARGIN: 0in 0in 0pt 0.25in"><FONT style=": #e6e6e6"><FONT face="Courier New"><strong><FONT color=#808080>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT><SPAN style="COLOR: blue">if</SPAN><FONT color=#808080> ((</FONT><SPAN style="COLOR: teal">DateTime</SPAN><FONT color=#808080>.Now - mLastPolledTime) &gt;= </FONT><SPAN style="COLOR: blue">new</SPAN><FONT color=#808080> </FONT><SPAN style="COLOR: teal">TimeSpan</SPAN><FONT color=#808080>(0, 0, 10)) {</FONT></strong></FONT></FONT></P><P =CodeSnippet style="MARGIN: 0in 0in 0pt 0.25in"><FONT style=": #e6e6e6" face="Courier New" color=#808080><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mTotalRevenue = CalculateTotalRevenue();</strong></FONT></P><P =CodeSnippet style="MARGIN: 0in 0in 0pt 0.25in"><FONT style=": #e6e6e6"><FONT face="Courier New"><strong><FONT color=#808080>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mLastPolledTime = </FONT><SPAN style="COLOR: teal">DateTime</SPAN><FONT color=#808080>.Now;</FONT></strong></FONT></FONT></P><P =CodeSnippet style="MARGIN: 0in 0in 0pt 0.25in"><FONT style=": #e6e6e6" face="Courier New" color=#808080><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</strong></FONT></P><P =CodeSnippet style="MARGIN: 0in 0in 0pt 0.25in"><FONT style=": #e6e6e6"><FONT face="Courier New"><strong><FONT color=#808080>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT><SPAN style="COLOR: blue">return</SPAN><FONT color=#808080> mTotalRevenue;</FONT></strong></FONT></FONT></P><P =CodeSnippet style="MARGIN: 0in 0in 0pt 0.25in"><FONT style=": #e6e6e6" face="Courier New" color=#808080><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</strong></FONT></P><P =CodeSnippet style="MARGIN: 0in 0in 0pt 0.25in"><FONT style=": #e6e6e6" face="Courier New" color=#808080><strong>&nbsp;&nbsp;&nbsp; }</strong></FONT></P><P =CodeSnippet style="MARGIN: 0in 0in 0pt 0.25in"><SPAN style="COLOR: navy; FONT-FAMILY: Arial"><o:p><FONT style=": #e6e6e6"><strong>&nbsp;</strong></FONT></o:p></SPAN></P><P =CodeSnippet style="MARGIN: 0in 0in 0pt 0.25in"><FONT style=": #e6e6e6"><strong><FONT face="Courier New"><FONT color=#808080>&nbsp;&nbsp;&nbsp; </FONT><SPAN style="COLOR: blue">private</SPAN><FONT color=#808080> </FONT><SPAN style="COLOR: blue">double</SPAN><FONT color=#808080> CalculateTotalRevenue() {</FONT></FONT></strong></FONT></P><P =CodeSnippet style="MARGIN: 0in 0in 0pt 0.25in"><FONT style=": #e6e6e6"><strong><FONT face="Courier New"><FONT color=#808080>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT><SPAN style="COLOR: green">// Create a Dynamic Entity Type without a primary key.<o:p></o:p></SPAN></FONT></strong></FONT></P><P =CodeSnippet style="MARGIN: 0in 0in 0pt 0.25in"><FONT style=": #e6e6e6"><strong><FONT face="Courier New"><FONT color=#808080>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT><SPAN style="COLOR: green">// Note: msType is only created once for this Employee type since this same dynamic type <o:p></o:p></SPAN></FONT></strong></FONT></P><P =CodeSnippet style="MARGIN: 0in 0in 0pt 0.25in"><FONT style=": #e6e6e6"><strong><FONT face="Courier New"><FONT color=#808080>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT><SPAN style="COLOR: green">// can be used for all subsequent calculations of an Employee's total order revenue.<o:p></o:p></SPAN></FONT></strong></FONT></P><P =CodeSnippet style="MARGIN: 0in 0in 0pt 0.25in"><FONT style=": #e6e6e6"><strong><FONT face="Courier New"><FONT color=#808080>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT><SPAN style="COLOR: blue">if</SPAN><FONT color=#808080> (msType == </FONT><SPAN style="COLOR: blue">null</SPAN><FONT color=#808080>) {</FONT></FONT></strong></FONT></P><P =CodeSnippet style="MARGIN: 0in 0in 0pt 0.25in"><FONT style=": #e6e6e6"><strong><FONT face="Courier New"><FONT color=#808080>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; msType = </FONT><SPAN style="COLOR: teal">DynamicEntityTypeBuilder</SPAN><FONT color=#808080>.CreateType(</FONT><SPAN style="COLOR: maro&#111;n">"TotalOrderRevenue"</SPAN><FONT color=#808080>, </FONT><SPAN style="COLOR: maro&#111;n">"Default"</SPAN><FONT color=#808080>);</FONT></FONT></strong></FONT></P><P =CodeSnippet style="MARGIN: 0in 0in 0pt 0.25in"><FONT style=": #e6e6e6" face="Courier New" color=#808080><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</strong></FONT></P><P =CodeSnippet style="MARGIN: 0in 0in 0pt 0.25in"><o:p><FONT style=": #e6e6e6" face="Courier New" color=#808080><strong>&nbsp;</strong></FONT></o:p></P><P =CodeSnippet style="MARGIN: 0in 0in 0pt 0.25in"><FONT style=": #e6e6e6"><strong><FONT face="Courier New"><FONT color=#808080>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT><SPAN style="COLOR: green">// Construct PassThruQuery specifying the SUM aggregate.<o:p></o:p></SPAN></FONT></strong></FONT></P><P =CodeSnippet style="MARGIN: 0in 0in 0pt 0.25in"><FONT style=": #e6e6e6"><strong><FONT face="Courier New"><FONT color=#808080>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT><SPAN style="COLOR: blue">string</SPAN><FONT color=#808080> sqlStmt = </FONT><SPAN style="COLOR: teal">String</SPAN><FONT color=#808080>.Format(</FONT><SPAN style="COLOR: maro&#111;n">"select SUM(OrderDetail.Quantity * OrderDetail.UnitPrice * OrderDetail.Discount) "</SPAN><FONT color=#808080> +</FONT></FONT></strong></FONT></P><P =CodeSnippet style="MARGIN: 0in 0in 0pt 0.25in"><FONT style=": #e6e6e6"><strong><FONT face="Courier New"><FONT color=#808080>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT><SPAN style="COLOR: maro&#111;n">"from Employee, OrderSummary, OrderDetail "</SPAN><FONT color=#808080> +</FONT></FONT></strong></FONT></P><P =CodeSnippet style="MARGIN: 0in 0in 0pt 0.25in"><FONT style=": #e6e6e6"><strong><FONT face="Courier New"><FONT color=#808080>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT><SPAN style="COLOR: maro&#111;n">"where Employee.Id = {0} and "</SPAN><FONT color=#808080> +</FONT></FONT></strong></FONT></P><P =CodeSnippet style="MARGIN: 0in 0in 0pt 0.25in"><FONT style=": #e6e6e6"><strong><FONT face="Courier New"><FONT color=#808080>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT><SPAN style="COLOR: maro&#111;n">"Employee.Id = OrderSummary.EmployeeId and "</SPAN><FONT color=#808080> +</FONT></FONT></strong></FONT></P><P =CodeSnippet style="MARGIN: 0in 0in 0pt 0.25in"><FONT style=": #e6e6e6"><strong><FONT face="Courier New"><FONT color=#808080>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT><SPAN style="COLOR: maro&#111;n">"OrderSummary.Id = OrderDetail.OrderSummaryId"</SPAN><FONT color=#808080>, </FONT><SPAN style="COLOR: blue">this</SPAN><FONT color=#808080>.Id);</FONT></FONT></strong></FONT></P><P =CodeSnippet style="MARGIN: 0in 0in 0pt 0.25in"><FONT style=": #e6e6e6"><strong><FONT face="Courier New"><FONT color=#808080>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT><SPAN style="COLOR: teal">IEntityQuery</SPAN><FONT color=#808080> query = </FONT><SPAN style="COLOR: blue">new</SPAN><FONT color=#808080> </FONT><SPAN style="COLOR: teal">PassthruRdbQuery</SPAN><FONT color=#808080>(msType, sqlStmt);</FONT></FONT></strong></FONT></P><P =CodeSnippet style="MARGIN: 0in 0in 0pt 0.25in"><FONT style=": #e6e6e6" face="Courier New" color=#808080><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </strong></FONT></P><P =CodeSnippet style="MARGIN: 0in 0in 0pt 0.25in"><FONT style=": #e6e6e6"><strong><FONT face="Courier New"><FONT color=#808080>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT><SPAN style="COLOR: green">// Retrieve list of entities based on the query.<o:p></o:p></SPAN></FONT></strong></FONT></P><P =CodeSnippet style="MARGIN: 0in 0in 0pt 0.25in"><FONT style=": #e6e6e6"><strong><FONT face="Courier New"><FONT color=#808080>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT><SPAN style="COLOR: teal">IList</SPAN><FONT color=#808080>&lt;</FONT><SPAN style="COLOR: teal">DynamicEntity</SPAN><FONT color=#808080>&gt; entities = </FONT><SPAN style="COLOR: blue">this</SPAN><FONT color=#808080>.PersistenceManager.GetEntities&lt;</FONT><SPAN style="COLOR: teal">DynamicEntity</SPAN><FONT color=#808080>&gt;(query);</FONT></FONT></strong></FONT></P><P =CodeSnippet style="MARGIN: 0in 0in 0pt 0.25in"><o:p><FONT style=": #e6e6e6" face="Courier New" color=#808080><strong>&nbsp;</strong></FONT></o:p></P><P =CodeSnippet style="MARGIN: 0in 0in 0pt 0.25in"><FONT style=": #e6e6e6"><strong><FONT face="Courier New"><FONT color=#808080>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT><SPAN style="COLOR: green">// Result is in the first entity's first column.<o:p></o:p></SPAN></FONT></strong></FONT></P><P =CodeSnippet style="MARGIN: 0in 0in 0pt 0.25in"><FONT style=": #e6e6e6"><strong><FONT face="Courier New"><FONT color=#808080>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT><SPAN style="COLOR: blue">return</SPAN><FONT color=#808080> ( (entities&#091;0&#093;&#091;0&#093; </FONT><SPAN style="COLOR: blue">is</SPAN><FONT color=#808080> System.</FONT><SPAN style="COLOR: teal">DBNull</SPAN><FONT color=#808080>) ? 0 : (</FONT><SPAN style="COLOR: blue">double</SPAN><FONT color=#808080>)entities&#091;0&#093;&#091;0&#093; );</FONT></FONT></strong></FONT></P><P =CodeSnippet style="MARGIN: 0in 0in 0pt 0.25in"><strong><FONT style=": #e6e6e6" face="Courier New" color=#808080>&nbsp;&nbsp;&nbsp; }</FONT></strong></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><SPAN style="COLOR: navy; FONT-FAMILY: Arial; mso-bidi-font-size: 10.0pt"><o:p>&nbsp;</o:p></SPAN></P><P =Ms&#111;normal style="MARGIN: 8pt 0in 0pt 0.25in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo3; tab-stops: list .25in"><SPAN style="mso-list: Ignore">(1)<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN>In the Getter for Employee.TotalOrderRevenue, I added a “guard clause” (for illustrative purposes) if you are concerned about performance. It will limit the calculation to once every 10 seconds.<SPAN style="FONT-SIZE: 12pt"> </SPAN></P><P =Ms&#111;normal style="MARGIN: 8pt 0in 0pt 0.25in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo3; tab-stops: list .25in"><SPAN style="mso-list: Ignore">(2)<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN>The dynamic entity type, msType, is created once per Employee class. </P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><SPAN style="COLOR: navy; FONT-FAMILY: Arial; mso-bidi-font-size: 10.0pt"><o:p>&nbsp;</o:p></SPAN></P><P =Ms&#111;normal style="MARGIN: 8pt 0in 0pt">You can create dynamic types with or without a primary key. Dynamic entity types <I>with a primary key</I> operate almost exactly like a statically defined DevForce entity type. Query results are merged into PM according to the query’s MergeStrategy. In the example above, I created a type <I>without a primary key</I>. Results will not be merged. The PM will first discard all prior instances of the type and then fill the cache with the query results. Because we only care about the computed value for a given Employee, this is the way to go.</P><P =Ms&#111;normal style="MARGIN: 8pt 0in 0pt">You can define the schema for the dynamic entity type in 2 ways:</P><OL style="MARGIN-TOP: 0in" =1><LI =Ms&#111;normal style="MARGIN: 8pt 0in 0pt; mso-list: l2 level1 lfo5; tab-stops: list .5in">By declaring it programmatically. See the Developer’s Guide for examples on the 5 overloads of the DynamicEntityTypeBuilder.CreateType method.<SPAN style="FONT-SIZE: 12pt"> </SPAN></LI><LI =Ms&#111;normal style="MARGIN: 8pt 0in 0pt; mso-list: l2 level1 lfo5; tab-stops: list .5in">By defining and executing a query for the type (shown here).<SPAN style="FONT-SIZE: 12pt"> </SPAN></LI></OL><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt 0.25in"><SPAN style="COLOR: navy; FONT-FAMILY: Arial; mso-bidi-font-size: 10.0pt"><o:p>&nbsp;</o:p></SPAN></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt 0.25in"><SPAN style="COLOR: navy; FONT-FAMILY: Arial; mso-bidi-font-size: 10.0pt"><o:p>&nbsp;</o:p></SPAN></P><P =Ms&#111;normal style="MARGIN: 8pt 0in 0pt 0.25in; TEXT-INDENT: -0.25in; mso-list: l3 level1 lfo4; tab-stops: list .25in"><SPAN style="mso-list: Ignore">1.<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN>A PassThruQuery is then constructed containing the SUM aggregate.<SPAN style="FONT-SIZE: 12pt"> </SPAN></P><P =Ms&#111;normal style="MARGIN: 8pt 0in 0pt 0.25in; TEXT-INDENT: -0.25in; mso-list: l3 level1 lfo4; tab-stops: list .25in"><SPAN style="mso-list: Ignore">2.<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN>The list of entities is retrieved based on the query.<SPAN style="FONT-SIZE: 12pt"> </SPAN></P><P =Ms&#111;normal style="MARGIN: 8pt 0in 0pt 0.25in; TEXT-INDENT: -0.25in; mso-list: l3 level1 lfo4; tab-stops: list .25in"><SPAN style="mso-list: Ignore">3.<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN>The result is returned in the first record’s first column.<SPAN style="FONT-SIZE: 12pt"> </SPAN></P><P =Ms&#111;normal style="MARGIN: 8pt 0in 0pt 0.25in; TEXT-INDENT: -0.25in; mso-list: l3 level1 lfo4; tab-stops: list .25in"><SPAN style="mso-list: Ignore">4.<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN>You can now bind to Employee.TotalOrderRevenue just as you would any other custom property.</P><P =Ms&#111;normal style="MARGIN: 8pt 0in 0pt">For more details on dynamic entities, please reference the chapter titled “Dynamic Enitity Types” in the Developer’s Guide.</P><P style="MARGIN: 8pt 0in 0pt" ="Ms&#111;normal"></FONT>&nbsp;</P><span style="font-size:10px"><br /><br />Edited by IdeaBlade - 06-Jun-2007 at 12:55pm</span>]]>
   </description>
   <pubDate>Wed, 06 Jun 2007 12:54:20 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=43&amp;PID=108#108</guid>
  </item> 
  <item>
   <title>Computing Aggregate Values Efficiently with Dynamic Entities : Question:  What are your best...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=43&amp;PID=107#107</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=20" rel="nofollow">Customer</a><br /><strong>Subject:</strong> 43<br /><strong>Posted:</strong> 06-Jun-2007 at 12:53pm<br /><br /><P style="MARGIN: 0in 0in 0pt" ="Questi&#111;n"><strong><EM><FONT face="Times New Roman" size=3>Question: </FONT></EM></strong></P><P style="MARGIN: 8pt 0in 0pt" ="Ms&#111;normal"><FONT face="Times New Roman" size=2>What are your best practice recommendations for data retrieval dependent on aggregate functions?&nbsp; In our case, an Invoice object has a custom property called Balance which is calculated on the fly as (the Gross Revenue<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>– (the Sum of the Payments)).&nbsp; Is this best performed in a stored procedure object?&nbsp;</FONT><SPAN style="COLOR: blue"><FONT face="Times New Roman" size=2>&nbsp;</FONT><BR style="mso-special-character: line-break"><BR style="mso-special-character: line-break"><?:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><O:P></P><P style="MARGIN: 8pt 0in 0pt" ="Ms&#111;normal"><FONT face="Times New Roman" color=#000000 size=2>Contains an Employee class that demonstrates the use of a DynamicEntity type and a PassThruQuery containing an aggregate SUM function. </FONT></P></O:P></SPAN><span style="font-size:10px"><br /><br />Edited by Customer - 06-Jun-2007 at 12:56pm</span>]]>
   </description>
   <pubDate>Wed, 06 Jun 2007 12:53:10 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=43&amp;PID=107#107</guid>
  </item> 
 </channel>
</rss>