<?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 : why would Importing an entity fail?</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : Community Forum now on StackOverflow : why would Importing an entity fail?</description>
  <pubDate>Mon, 13 Apr 2026 12:08:41 -700</pubDate>
  <lastBuildDate>Mon, 28 Apr 2014 19:14:16 -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=4688</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>why would Importing an entity fail? : Sorry, I missed that you are creating...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=4688&amp;PID=17540#17540</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> 4688<br /><strong>Posted:</strong> 28-Apr-2014 at 7:14pm<br /><br />Sorry, I missed that you are creating a new EntityManager upon each add.&nbsp;<div><br></div><div>If that's the case, the next thing to debug is, make sure the Import succeeds, and right after the import, search the EM's cache by using the EntityManager.FindEntities method. This should only return 1 entity of type Memo and that its EntityKey is what you'd expect.</div>]]>
   </description>
   <pubDate>Mon, 28 Apr 2014 19:14:16 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=4688&amp;PID=17540#17540</guid>
  </item> 
  <item>
   <title>why would Importing an entity fail? : What i dont understand is that...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=4688&amp;PID=17539#17539</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=202" rel="nofollow">BillG</a><br /><strong>Subject:</strong> 4688<br /><strong>Posted:</strong> 28-Apr-2014 at 3:17pm<br /><br />What i dont understand is that when i pop up the dialog box for Memo form i am creating a new repository before importing the passed in memo object. Why would the previous one still be there? <br><br>going back to my example. on the list form, the user clicks Add, i create the memo and pass it to the dialog box form. in the dialog box form, i create a new repository/entity manager, import the passed in memo to the newly created entity manager. if i create a new repository/entity manager, clear it of all memos, and then do the import, should not that one be the only memo in the cache?<br><br>Bill<br><br><br><br>]]>
   </description>
   <pubDate>Mon, 28 Apr 2014 15:17:32 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=4688&amp;PID=17539#17539</guid>
  </item> 
  <item>
   <title>why would Importing an entity fail? : As you&amp;#039;ve already noticed,...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=4688&amp;PID=17538#17538</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> 4688<br /><strong>Posted:</strong> 28-Apr-2014 at 2:43pm<br /><br /><div>As you've already noticed, DevForce will generate a temporary key for entity with a PK identity column.</div><div><br></div>Entities with temporary key and EntityState of Added are considered new entities by the EntityManager. What this means is that when you import entities with the same id and EntityState of Added, the later import doesn't overwrite the earlier import. But rather, the EntityManager will see the later entity as a new entity and will increment the id. So what you have are 2 entities with different ids.<br><div><br></div><div>I suspect that this is what's happening here. The fix is to set the EntityState to Unchanged before import and set them back to Added before persisting them to the db.</div>]]>
   </description>
   <pubDate>Mon, 28 Apr 2014 14:43:38 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=4688&amp;PID=17538#17538</guid>
  </item> 
  <item>
   <title>why would Importing an entity fail? : yes. It is an identity column.  ...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=4688&amp;PID=17535#17535</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=202" rel="nofollow">BillG</a><br /><strong>Subject:</strong> 4688<br /><strong>Posted:</strong> 28-Apr-2014 at 12:21pm<br /><br />yes. It is an identity column.<br><br>]]>
   </description>
   <pubDate>Mon, 28 Apr 2014 12:21:38 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=4688&amp;PID=17535#17535</guid>
  </item> 
  <item>
   <title>why would Importing an entity fail? : Hi BillG,Are you using an integer...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=4688&amp;PID=17534#17534</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> 4688<br /><strong>Posted:</strong> 28-Apr-2014 at 11:53am<br /><br />Hi BillG,<div><br></div><div>Are you using an integer data type with Database Identity generation for your Memo's primary key?</div>]]>
   </description>
   <pubDate>Mon, 28 Apr 2014 11:53:54 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=4688&amp;PID=17534#17534</guid>
  </item> 
  <item>
   <title>why would Importing an entity fail? : I have the following situation....</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=4688&amp;PID=17532#17532</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=202" rel="nofollow">BillG</a><br /><strong>Subject:</strong> 4688<br /><strong>Posted:</strong> 27-Apr-2014 at 12:30am<br /><br />I have the following situation. the uses clicks an add button on a form. I create the entity for the add button in question lets say "Memo"<br /><br />var memo = Repository.CreateMemo(member);<br /><br />then I call my dialog box to display the memo<br /><br />MemoEditForm form = new MemoEditForm(memo);<br />DialogResult result = form.ShowDialog()<br /><br />in the constructor for the MemoEditForm. I have the following.<br /><br />  InitializeComponent();<br />  Repository = UnionRepository.CreateRepository();<br />  Repository.ClearAllMemberMemos();<br />  currentMemo = Repository.ImportMemberMemo(memo);<br />  editMode = memo.EntityAspect.EntityState == EntityState.Added ? EditMode.Add : EditMode.Edit;<br />  MemberMemoBS.DataSource = currentMemo;<br />  currentMember = currentMemo.Member;<br />  LoadData();<br /><br />basically I create a new repository/entity manager. I make sure the entity manager is clear. I import the passed over newly created memo object and import it into the new entity manager. if the user enters all the fields in and then clicks "Save" I close the dialog box and refresh a grid with the new memo. If they click cancel, I remove the entity from the first cache.<br /><br />This works for the first memo. I add a memo (I click cancel). I click add again and the import this time returns a null for currentMemo.<br /><br />so my question is why would the import fail. this is my import method<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public MemberMemo ImportMemberMemo(MemberMemo memo)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (memo == null || memo.EntityAspect.IsNullOrPendingEntity)<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;  throw new ArgumentException("Imported memo is null or nullo");<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;// Don't bother if already attached to repository's manager<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (memo.EntityAspect.EntityManager == Manager) return memo;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ImportEntities(new Object&#091;&#093; { memo });<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return (MemberMemo)Manager.FindEntity(memo.EntityAspect.EntityKey);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;private void ImportEntities(IEnumerable entities)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;EnsureEntitiesAreUnmodified(entities);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Manager.ImportEntities(entities, MergeStrategy.OverwriteChanges);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />]]>
   </description>
   <pubDate>Sun, 27 Apr 2014 00:30:29 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=4688&amp;PID=17532#17532</guid>
  </item> 
 </channel>
</rss>