<?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 : Is changing Primary Keys supported?</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : DevForce 2010 : Is changing Primary Keys supported?</description>
  <pubDate>Sun, 12 Apr 2026 05:41:42 -700</pubDate>
  <lastBuildDate>Mon, 27 Jun 2011 16:39:17 -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=2797</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>Is changing Primary Keys supported? : Thank you for the feedback John....</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2797&amp;PID=11131#11131</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=912" rel="nofollow">DenisK</a><br /><strong>Subject:</strong> 2797<br /><strong>Posted:</strong> 27-Jun-2011 at 4:39pm<br /><br />Thank you for the feedback John. We already have some write up regarding this but instead of using the word "primary key", we had used the word "EntityKey" which is DevForce implementation of an entity's primary key.<div><br></div><div><a href="http://drc.ideablade.com/xwiki/bin/view/&#068;ocumentati&#111;n/entity-modificati&#111;n#HMiscellaneoustopics" target="_blank">http://drc.ideablade.com/xwiki/bin/view/Documentation/entity-modification#HMiscellaneoustopics</a></div><div><br></div><div>I'll submit a request to improve the DRC search engine for this.</div>]]>
   </description>
   <pubDate>Mon, 27 Jun 2011 16:39:17 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2797&amp;PID=11131#11131</guid>
  </item> 
  <item>
   <title>Is changing Primary Keys supported? : Thanks Denis, Yes, it was Defect...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2797&amp;PID=11127#11127</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1181" rel="nofollow">jradxl</a><br /><strong>Subject:</strong> 2797<br /><strong>Posted:</strong> 27-Jun-2011 at 3:52pm<br /><br />Thanks Denis,<br>Yes, it was Defect #1 that I couldn't believe, and so true about Defect #2's message being confusing.<br>I only hope you don't add exceptions in non-accessable places so users of your libraries like me cannot intercept these changes.<br>For me I hope I can still use EntityServerSaveInterceptor.<br><br>I think a paragraph in your documentation would be advisable, as my searches didn't come up with anything that convinced me what the current situation is.<br><br>rgds<br>John]]>
   </description>
   <pubDate>Mon, 27 Jun 2011 15:52:51 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2797&amp;PID=11127#11127</guid>
  </item> 
  <item>
   <title>Is changing Primary Keys supported? : Hi John;Unfortunately, no, it&amp;#039;s...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2797&amp;PID=11117#11117</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=912" rel="nofollow">DenisK</a><br /><strong>Subject:</strong> 2797<br /><strong>Posted:</strong> 27-Jun-2011 at 12:06pm<br /><br />Hi John;<div><br></div><div>Unfortunately, no, it's not supported, but there is a workaround. We had to respond to another customer having a similar question the other day. Here's a copy paste of that response written by Ward Bell. The workaround is provided at the end.</div><div><br></div><div><table width="99%"><tr><td class="BBquote"></div><div><p ="Ms&#111;normal"><b><span style="font-size:14.0pt;color:#1F497D">#1&nbsp;&nbsp;An application cannot change the primary key (PK) of an existing(already saved) entity.<o:p></o:p></span></b></p><p ="Ms&#111;normal"><span style="color:#1F497D"><o:p>&nbsp;</o:p></span></p><p ="Ms&#111;normal"><span style="color:#1F497D">It makes no difference whetherthe PK is composite or single valued … you just can’t do it.<o:p></o:p></span></p><p ="Ms&#111;normal"><span style="color:#1F497D"><o:p>&nbsp;</o:p></span></p><p ="Ms&#111;normal"><span style="color:#1F497D">My recollection is that EFprohibits changes to the PK but I’m not certain. We do know that allowing achange to the PK invites numerous unfortunate consequences when the PK of thechanged entity is the foreign key of other, child entities. &nbsp;Consider theeffect on Order-Line-items of changing the ID of its parent Order. The databasecould detect a FK violation and throw an exception; it might not in which caseyou’ve orphaned the child line items. <o:p></o:p></span></p><p ="Ms&#111;normal"><span style="color:#1F497D"><o:p>&nbsp;</o:p></span></p><p ="Ms&#111;normal"><span style="color:#1F497D">We agree that DF does notproperly report the error when the application tries to change the PK<o:p></o:p></span></p><p ="Ms&#111;normal"><span style="color:#1F497D"><o:p>&nbsp;</o:p></span></p><p ="Ms&#111;normal" style="margin-left:.5in"><span style="color:#1F497D">DFdefect #1: We should throw a clear exception when you try to save an updatedentity with a pending change to the PK. Instead, the save appears to succeedalthough it did not.<o:p></o:p></span></p><p ="Ms&#111;normal" style="margin-left:.5in"><span style="color:#1F497D"><o:p>&nbsp;</o:p></span></p><p ="Ms&#111;normal" style="margin-left:.5in"><span style="color:#1F497D">DFdefect #2: We do throw an exception if you try to save an updated entity with apending change to the PK and at least one other property. Unfortunately, (a) werely on the server to produce the exception when we could detect it on theclient and (b) the wording of the exception is not clear about the cause or theresolution.<o:p></o:p></span></p><p ="Ms&#111;normal"><span style="color:#1F497D"><o:p>&nbsp;</o:p></span></p><p ="Ms&#111;normal"><span style="color:#1F497D">We will correct these defects inour next release. But our no-PK-change rule is a deliberate choice in DF; wefeel the defects are in the reporting, not in the prohibition itself.<o:p></o:p></span></p><p ="Ms&#111;normal"><span style="color:#1F497D"><o:p>&nbsp;</o:p></span></p><p ="Ms&#111;normal"><b><span style="font-size:12.0pt;color:#1F497D">What to do?<o:p></o:p></span></b></p><p ="Ms&#111;normal"><span style="color:#1F497D"><o:p>&nbsp;</o:p></span></p><p ="Ms&#111;normal"><span style="color:#1F497D">All architects agree that oneshould never change the primary key of an existing entity. That said, we knowthat it happens, especially with legacy databases in which the key contains ameaningful value … such as some portion of an entity’s “name”.<o:p></o:p></span></p><p ="Ms&#111;normal"><span style="color:#1F497D"><o:p>&nbsp;</o:p></span></p><p ="Ms&#111;normal"><span style="color:#1F497D">If the app must be able tochange the entity PK, the only permitted way to do that is <o:p></o:p></span></p><p ="MsoListParagraph" style="text-indent:-.25in;mso-list:l0 level1 lfo1"><!--if !supLists--><span style="font-family:Symbol;mso-fareast-font-family:Symbol;mso-bidi-font-family:  Symbol;color:#1F497D"><span style="mso-list:Ignore">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;·<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span></span><!----><span style="color:#1F497D">copy the entity, <o:p></o:p></span></p><p ="MsoListParagraph" style="text-indent:-.25in;mso-list:l0 level1 lfo1"><!--if !supLists--><span style="font-family:Symbol;mso-fareast-font-family:Symbol;mso-bidi-font-family:  Symbol;color:#1F497D"><span style="mso-list:Ignore">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;·<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span></span><!----><span style="color:#1F497D">give it the revisedPK, <o:p></o:p></span></p><p ="MsoListParagraph" style="text-indent:-.25in;mso-list:l0 level1 lfo1"><!--if !supLists--><span style="font-family:Symbol;mso-fareast-font-family:Symbol;mso-bidi-font-family:  Symbol;color:#1F497D"><span style="mso-list:Ignore">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;·<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span></span><!----><span style="color:#1F497D">delete the original.<o:p></o:p></span></p><p ="Ms&#111;normal"><span style="color:#1F497D"><o:p>&nbsp;</o:p></span></p><p ="Ms&#111;normal"><span style="color:#1F497D">You can do this all in the sameEntityManager and submit these changes in the same save (so they are committedin the same transaction).<o:p></o:p></span></p><p ="Ms&#111;normal"><span style="color:#1F497D"><o:p>&nbsp;</o:p></span></p><p ="Ms&#111;normal"><span style="color:#1F497D">This insert+delete approach isopen to the same risks as I mentioned above: potential FK violations andorphaned children. But at least you had to work at “doing the wrong thing”.</span></p><p ="Ms&#111;normal"></td></tr></table></p></div>]]>
   </description>
   <pubDate>Mon, 27 Jun 2011 12:06:34 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2797&amp;PID=11117#11117</guid>
  </item> 
  <item>
   <title>Is changing Primary Keys supported? : Hi,Does DF (or EF) support the...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2797&amp;PID=11108#11108</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1181" rel="nofollow">jradxl</a><br /><strong>Subject:</strong> 2797<br /><strong>Posted:</strong> 25-Jun-2011 at 3:30pm<br /><br />Hi,<br>Does DF (or EF) support the changing of Primary &#091;Composite&#093; Key(s)?<br><br>Consider a Table with these three fields as a Composite Key.<br>1. EmployeeID<br>2. Date<br>3. SequenceNumber<br>as used in a HR system.<br>The User might (frequently in my experience) miss-key the date, and then has to correct the record just entered.<br><br>We can assume that the EmployeeID will not change (if that was wrong, the User is editing the wrong person, and will delete the row themselves), but the User would be expect to be able to change the Date and/or the SequenceNumber.<br><br>Do I need to code this in an EntityServerSaveInterceptor?<br><br>thanks<br>John<br><br><br>]]>
   </description>
   <pubDate>Sat, 25 Jun 2011 15:30:29 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2797&amp;PID=11108#11108</guid>
  </item> 
 </channel>
</rss>