<?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 : Insert into field same value as PK</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : DevForce 2010 : Insert into field same value as PK</description>
  <pubDate>Wed, 15 Apr 2026 09:04:00 -700</pubDate>
  <lastBuildDate>Wed, 05 Jan 2011 16:36: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=2366</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>Insert into field same value as PK : Guillermo, the other alternative...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2366&amp;PID=9569#9569</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=892" rel="nofollow">sbelini</a><br /><strong>Subject:</strong> 2366<br /><strong>Posted:</strong> 05-Jan-2011 at 4:36pm<br /><br /><P>Guillermo,</P><DIV>the other alternative I found is to implement a custom IIdGenerator, assign the IDs using </DIV><DIV><EM>mgr.GenerateId(myTestEntity, TestEntity.PropertyMetadata.Id);</EM></DIV><DIV>and call</DIV><DIV><EM>mgr.ForceIdFixup();</EM></DIV><DIV>right before calling the save.</DIV><DIV>This way you can implement your checking in the SaveInterceptor.</DIV><DIV>&nbsp;</DIV><DIV>We have a&nbsp;simple custom IIdGenerator implemented in our samples in our <a href="http://drc.ideablade.com/xwiki/bin/view/&#068;ocumentati&#111;n/Code_MiniDemosSilverlight_BusObjPersistence" target="_blank">DevForce Resource Center</A>&nbsp;(you can find it at <EM>030_BusObjPersistence\_MiniDemos\Silverlight\CodeCS\SilverlightConsole.sln</EM> among other solutions)</DIV><DIV>&nbsp;</DIV><DIV>Silvio</DIV>]]>
   </description>
   <pubDate>Wed, 05 Jan 2011 16:36:17 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2366&amp;PID=9569#9569</guid>
  </item> 
  <item>
   <title>Insert into field same value as PK :  Hi sbelini,I forgot to mention...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2366&amp;PID=9395#9395</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=825" rel="nofollow">gkneo</a><br /><strong>Subject:</strong> 2366<br /><strong>Posted:</strong> 13-Dec-2010 at 11:54pm<br /><br />Hi sbelini,<div><br></div><div>I forgot to mention that Id field is an identity field, so &nbsp;the line&nbsp;</div><div><table width="99%"><tr><td><pre class="BBcode"></div><div><span ="apple-style-span"="" style="font-family: 'Courier New', Courier, mono; line-height: 18px; font-size: small; -webkit-border-horiz&#111;ntal-spacing: 1px; -webkit-border-vertical-spacing: 1px; ">&nbsp;myEntity.CheckField =&nbsp;myEntity.Id;</span></div><div></pre></td></tr></table></div><div>will store "-101" in CheckField. &nbsp;</div><div><br></div><div>This was the first thing I tried, but I am sorry I didn't mention it in my original post.</div><span style="font-size:10px"><br /><br />Edited by gkneo - 13-Dec-2010 at 11:57pm</span>]]>
   </description>
   <pubDate>Mon, 13 Dec 2010 23:54:50 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2366&amp;PID=9395#9395</guid>
  </item> 
  <item>
   <title>Insert into field same value as PK : Hi Guillermo,  You could do...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2366&amp;PID=9385#9385</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=892" rel="nofollow">sbelini</a><br /><strong>Subject:</strong> 2366<br /><strong>Posted:</strong> 13-Dec-2010 at 10:09am<br /><br />Hi Guillermo,<br><br>You could do your checking once you call SaveChangesAsync by implementing the EntityServerSaveInterceptor. <br>You can override the ExecuteSave method, and modify the value of CheckField before calling the base implementation of the ExecuteSave method:<br><br><font face="Courier New, Courier, mono" size="2">public class EntityServerSaveManager : EntityServerSaveInterceptor {<br>&nbsp;&nbsp;&nbsp; protected override bool ExecuteSave() {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var em = EntityManager;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var savedEntities = em.FindEntities(EntityState.Added).OfType&lt;MyEntityType&gt;();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach (MyEntityType myEntity in savedEntities) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (any criteria deciding what goes on CheckField) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myEntity.CheckField = myEntity.Id;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myEntity.CheckField = something_else;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return base.ExecuteSave();<br>&nbsp;&nbsp;&nbsp; }<br>}</font><br><br>You can find detailed information about Save Interception in our <a href="http://drc.ideablade.com/xwiki/bin/view/&#068;ocumentati&#111;n/SecurityIntercepti&#111;n" target="_blank">DevForce Resource Center</a>.<br><br>In addition, EntityManager saves are transactional by default. You can find out more about transactions and DevForce in the <a href="http://drc.ideablade.com/xwiki/bin/view/&#068;ocumentati&#111;n/Saving_Transacti&#111;ns" target="_blank">DevForce Resource Center</a> as well.<br><br>sbelini.<br>]]>
   </description>
   <pubDate>Mon, 13 Dec 2010 10:09:31 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2366&amp;PID=9385#9385</guid>
  </item> 
  <item>
   <title>Insert into field same value as PK : Hi. I have a table with 2 fields:Id:...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2366&amp;PID=9360#9360</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=825" rel="nofollow">gkneo</a><br /><strong>Subject:</strong> 2366<br /><strong>Posted:</strong> 10-Dec-2010 at 2:41am<br /><br />Hi. &nbsp;<div><br></div><div>I have a table with 2 fields:</div><div><br></div><div>Id: int pk</div><div>CheckField: nvarchar(20)</div><div>ControlField: nchar(1)</div><div><br></div><div><br></div><div>I have created my devforce entity A from this table.</div><div>Now, I want to create and insert &nbsp;a list of entities of type A. &nbsp;I want to store in CheckField the same value from Id, but sometimes (depends upon some business logic), I want to store any value. &nbsp;So, I would have something like this:</div><div><table width="99%"><tr><td><pre class="BBcode"></div><div>Id&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;CheckField&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;ControlField</div><div>1 &nbsp; &nbsp; &nbsp;1&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;A</div><div>2&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;2&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; A</div><div>3&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;0000XYZ&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;B</div><div>4&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;4&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;A</div><div>5&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;5&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;A</div><div>6&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;0000FGH&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;B</div><div></pre></td></tr></table></div><div><br></div><div>Is it possible to achieve using a SaveChangesAsync? &nbsp;I want to do this in a single transaction, and cannot use stored procedures (architectural decision)</div><div><br></div><div>Guillermo</div>]]>
   </description>
   <pubDate>Fri, 10 Dec 2010 02:41:15 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2366&amp;PID=9360#9360</guid>
  </item> 
 </channel>
</rss>