<?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 : StoreGeneratedPattern - Is this supported?</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : DevForce 2010 : StoreGeneratedPattern - Is this supported?</description>
  <pubDate>Tue, 21 Apr 2026 14:10:02 -700</pubDate>
  <lastBuildDate>Thu, 24 Jun 2010 18:07:38 -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=1904</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>StoreGeneratedPattern - Is this supported? :   A temporary (but slightly...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1904&amp;PID=7415#7415</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=485" rel="nofollow">jsobell</a><br /><strong>Subject:</strong> 1904<br /><strong>Posted:</strong> 24-Jun-2010 at 6:07pm<br /><br />A temporary (but slightly dodgy) workaroundfor the TimeStamp properties is as follows.<br>However, I can't see any way of accessing the fact it is specifically a TimeStamp field (this example is assuming all Byte&#091;&#093; fields are timestamps), and it doesn't even touch on the Default problem above.<br>I could have used the field name "ts" for all timestamps, but the ideal would be to know the underlying database type.<br><br><font face="Courier New, Courier, mono">&nbsp;&nbsp;&nbsp; public class QsEntitySaveInterceptor : EntityServerSaveInterceptor<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; protected override bool ValidateSave()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var now = DateTime.Now;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var e = base.EntityManager.FindEntities(EntityState.Added).Cast&lt;Entity&gt;().ToList();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach(var entity in e)<br>&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; var timestamps = (entity).EntityAspect.EntityMetadata.EntityProperties.Where(ep =&gt; ep.DataType == typeof(byte&#091;&#093;));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach (var prop in timestamps)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; prop.PropertyInfo.SetValue(entity, new byte&#091;&#093; { 0, 0, 0, 0, 0, 0, 0, 0 }, null);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var createddates = (entity).EntityAspect.EntityMetadata.EntityProperties.Where(ep =&gt; ep.Name == "DateCreated" || ep.Name == "LastUpdated");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach (var prop in createddates)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; prop.PropertyInfo.SetValue(entity, now, null);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return base.ValidateSave();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }</font><br><br>So... interesting questions:<br><ul><li>is there any way to find the database type that underlies an Entity property?</li><li>is it right that DateTime fields on new Entities are always set to Today? This might be dangerous; forgetting to set it in code might not be detected, and what if we want to know in the Save Interceptor whether a value was entered or not? Might a date of DateTime.Min (or 01-01-1900 for non-DateTime2) not be better?<br>Also, non-nullable string fields don't have a default of String.Empty, so why are DateTimes set to a value?<br></li><li>do you know of any way to make the EF4 designer retrieve other SQL metadata such as 'Default Value or Binding'?</li><li>is it possible to influence the SQL of fields that will be inserted on added entities (i.e. remove inserted parameters so defaults are used)?</li></ul>Ah, so many questions and so little time to answer them all...<br><br><span style="font-size:10px"><br /><br />Edited by jsobell - 24-Jun-2010 at 6:09pm</span>]]>
   </description>
   <pubDate>Thu, 24 Jun 2010 18:07:38 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1904&amp;PID=7415#7415</guid>
  </item> 
  <item>
   <title>StoreGeneratedPattern - Is this supported? : The issue here is that by modifying...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1904&amp;PID=7384#7384</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=485" rel="nofollow">jsobell</a><br /><strong>Subject:</strong> 1904<br /><strong>Posted:</strong> 22-Jun-2010 at 9:31pm<br /><br />The issue here is that by modifying (or correcting) the attributes in the EDMX file, EF4 is able to cope with these properties in an acceptable manner.<br>EF4 also handles timestamps correctly. These should never be written to the tables, yet DF seems to insist that a value be written.<br><br>So the most important issues here seem to be:<br><ul><li>Having to modify the base elements for 200 properties on 50 entities in a database is not sensible.</li><li>There are some behaviors that cannot be performed in the EntityServerSaveInterceptor. For example, if we are using a default of NewSequentialId() in a column, this cannot be generated by C#.</li><li>If the time is different between Server and Website then dangerous situations can arise (such as data marked as being modified later than its deletion date)</li></ul>I know that even persisting the values correctly in EF is still not ideal, but it is significantly better than the issues above.<br><br>Any other suggestions?<br>]]>
   </description>
   <pubDate>Tue, 22 Jun 2010 21:31:49 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1904&amp;PID=7384#7384</guid>
  </item> 
  <item>
   <title>StoreGeneratedPattern - Is this supported? : Yes, as you noticed: 1) The Entity...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1904&amp;PID=7383#7383</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=477" rel="nofollow">ting</a><br /><strong>Subject:</strong> 1904<br /><strong>Posted:</strong> 22-Jun-2010 at 9:06pm<br /><br />Yes, as you noticed:<DIV>1) &nbsp;The Entity Framework designer has an issue with setting StoreGeneratedPattern=Computed.</DIV><DIV>2)&nbsp; Even if this setting persisted correctly, it still doesn't give you the behavior you are looking for because it would always overwrite any provided value.</DIV><DIV>&nbsp;</DIV><DIV>If I read your post correctly, you can accomplish this behavior in DevForce by using&nbsp;the EntityServerSaveInterceptor.&nbsp; There, you can inspect the objects just before saving on the server, and update any audit information about the entity prior to the transaction.</DIV><DIV>&nbsp;</DIV><DIV>&nbsp;</DIV>]]>
   </description>
   <pubDate>Tue, 22 Jun 2010 21:06:07 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1904&amp;PID=7383#7383</guid>
  </item> 
  <item>
   <title>StoreGeneratedPattern - Is this supported? : Ping! Quite important for us! ...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1904&amp;PID=7378#7378</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=485" rel="nofollow">jsobell</a><br /><strong>Subject:</strong> 1904<br /><strong>Posted:</strong> 22-Jun-2010 at 4:38pm<br /><br />Ping! Quite important for us!]]>
   </description>
   <pubDate>Tue, 22 Jun 2010 16:38:06 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1904&amp;PID=7378#7378</guid>
  </item> 
  <item>
   <title>StoreGeneratedPattern - Is this supported? : In one of our EF4 based projects...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1904&amp;PID=7369#7369</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=485" rel="nofollow">jsobell</a><br /><strong>Subject:</strong> 1904<br /><strong>Posted:</strong> 21-Jun-2010 at 9:29pm<br /><br />In one of our EF4 based projects we just hit the old 'StoreGeneratedPattern' bug in VS2010, where it doesn't correctly set the attribute in the SSDL area for columns that have a 'Default Value or Binding' set.<br>However, the EF4 fix/bodge of adding 'StoreGeneratedPattern=Computed' doesn't cut the mustard; the purpose of this field is to specify what should be inserted in this field <u>if no value has been provided</u>.<br><br>Ideally we need a new enum in the EF4 set; StoreGeneratedPattern.DefaultValue or something.<br><br>So I decided to try the same thing in DF2010...<br><br>As an example, I have a table with three columns:<br><font face="Courier New, Courier, mono">Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; nvarchar(50)<br>LastEdited&nbsp; DateTime (Default = GetDate())<br>ts&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TimeStamp</font><br><br>Now when I generate the edmx, it sets ts to StoreGeneratedPattern=Computed, but ignores LastEdited.<br>However, a simple creation of this entity, set the name, AddEntity, then call SaveChanges complains (unlike EF4) that 'ts' must be supplied. Of course I can supply with with a dummy array of byte&#091;8&#093; which is ignored...<br><br>I'm sure I can bodge up the underlying entity through partial classes and property interceptors, but I'm sure this is not the intended method of reflecting the database structure. I was hoping DF would help with the second issue I mention, but we appear to have tripped at the first!<br><br>]]>
   </description>
   <pubDate>Mon, 21 Jun 2010 21:29:58 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1904&amp;PID=7369#7369</guid>
  </item> 
 </channel>
</rss>