<?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 : Error when saving entity</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : DevForce 2010 : Error when saving entity</description>
  <pubDate>Tue, 21 Apr 2026 15:49:23 -700</pubDate>
  <lastBuildDate>Thu, 22 Jul 2010 07:19:40 -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=1842</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>Error when saving entity : This will also happen if you have...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1842&amp;PID=7748#7748</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=704" rel="nofollow">mikewishart</a><br /><strong>Subject:</strong> 1842<br /><strong>Posted:</strong> 22-Jul-2010 at 7:19am<br /><br />This will also happen if you have a datetime as part of a primary key in SQLServer.&nbsp; The milliseconds value will be changed when the record is stored due to the accuracy being rounded to 0.000, 0.003 or 0.007 (depending on your setting).&nbsp; Just trim off the milliseconds.<br>]]>
   </description>
   <pubDate>Thu, 22 Jul 2010 07:19:40 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1842&amp;PID=7748#7748</guid>
  </item> 
  <item>
   <title>Error when saving entity : Thanks. That was indeed the problem...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1842&amp;PID=7593#7593</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=662" rel="nofollow">dpollot44</a><br /><strong>Subject:</strong> 1842<br /><strong>Posted:</strong> 12-Jul-2010 at 7:12am<br /><br />Thanks.&nbsp; That was indeed the problem (however, since we're pointing to an informix database, the char field is not necessarily 10.&nbsp; In my case it was 12, but it'll wind up being whatever it was defined to be).]]>
   </description>
   <pubDate>Mon, 12 Jul 2010 07:12:26 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1842&amp;PID=7593#7593</guid>
  </item> 
  <item>
   <title>Error when saving entity : Here was the resolution to Nitin&amp;#039;s...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1842&amp;PID=7585#7585</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=23" rel="nofollow">davidklitzke</a><br /><strong>Subject:</strong> 1842<br /><strong>Posted:</strong> 09-Jul-2010 at 3:29pm<br /><br />Here was the resolution to Nitin's problem:<DIV>&nbsp;</DIV><DIV>The <strong><EM>problem is that your entity's database key is a char type, which is always going to be a fixed length of 10. When you save a new instance with a key value like "Test4", that key gets converted to "Test4&nbsp;&nbsp;&nbsp;&nbsp; " by the database. When the entity with key "Test4&nbsp;&nbsp;&nbsp;&nbsp; " comes back to the Entity Framework (server-side), DevForce asks the EF to refresh the entities that were saved (so that they will include any changes made by triggers or such on the database, and thus will be accurate representations of what is in the database).&nbsp; But the EF looks for an entity with key "Test4&nbsp;&nbsp;&nbsp; " and doesn't find one, so it throws an exception.<BR><BR>There are two possible work-arounds:<BR><BR>1. Use an NCHAR key instead of CHAR so the database will accept the less-than-10-character value as is; OR<BR>2. Ensure that&nbsp;the value you give to a new entity for its key property is exactly 10 characters; .e.g.,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; table.UserName = ("Test" + number).PadRight(10);<BR><BR>It is possible to set DevForce (using a SaveOption)&nbsp;so that it does not order a refresh of the saved entity; but your use case actually represents a good example of why that's not a good idea. If DevForce weren't doing the refresh, you wouldn't know that you local entity had ended up, after the save,&nbsp;with a different key value than its corresponding database record.&nbsp; And that would make it impossible for you to update the record.<BR></EM></strong></DIV>]]>
   </description>
   <pubDate>Fri, 09 Jul 2010 15:29:05 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1842&amp;PID=7585#7585</guid>
  </item> 
  <item>
   <title>Error when saving entity : Has there been any answer to this?I&amp;#039;m...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1842&amp;PID=7582#7582</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=662" rel="nofollow">dpollot44</a><br /><strong>Subject:</strong> 1842<br /><strong>Posted:</strong> 09-Jul-2010 at 12:11pm<br /><br />Has there been any answer to this?<br>I'm running into the same error...<br><br>Suppose that we have two tables (and I'm just going to make up an example to protect the innocent) Libraries and Books.&nbsp; Libraries, within the entity data model will wind up having a conceptual model type of Library, and Books will have Book.&nbsp; A Library contains an identity column on it called Id, and likewise a Book has the same.&nbsp; Library also has a property/column LibraryCode which is a string (so from the store perspective - char/varchar/whatever).&nbsp; Book does NOT have a LibraryId integer column mapping it back to the Library, however it DOES have a LibraryCode property/column which is of the same char/varchar/whatever type property/column on the Library object.&nbsp; Now imagine that we decide to be unconventional in our construction of our Entity Model, and we decide that our Library's primary key will be "LibraryCode".&nbsp; We'll use "LibraryCode" to connect our two entities together - thereby creating a "Books" navigation property on Library, and a "Library" navigation property on Book.&nbsp; (Let's assume that in my world, a book can belong to at most one library.)<br><br>This situation seems to allow me to successfully load both Libary and Book entities from the data store, however, when I try to create a Library, it saves just fine but blows up in the end with error that's described in the previous post...<br><br>Any ideas?<br>]]>
   </description>
   <pubDate>Fri, 09 Jul 2010 12:11:45 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1842&amp;PID=7582#7582</guid>
  </item> 
  <item>
   <title>Error when saving entity : Hi  I am creating an Entity...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1842&amp;PID=7011#7011</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=632" rel="nofollow">ngoel</a><br /><strong>Subject:</strong> 1842<br /><strong>Posted:</strong> 24-May-2010 at 7:06pm<br /><br /><DIV>Hi</DIV><DIV>&nbsp;</DIV><DIV>I am creating an Entity and saving it to the database using:</DIV><DIV>&nbsp;</DIV><DIV><FONT size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas>EntityManager.SaveChanges();</DIV></FONT></FONT><DIV>&nbsp;</DIV><DIV>But, it is returning with the following error. The Entity is getting saved to the database but after it has saved the Entity to the database, it seems to be doing some refresh and failing. </DIV><DIV>&nbsp;</DIV><DIV>IdeaBlade.EntityModel.EntityManagerSaveException occurred<BR>&nbsp; Message=The refresh attempt has failed because an unexpected entity was returned by the data source.<BR>&nbsp; Source=IdeaBlade.EntityModel<BR>&nbsp; Cancelled=false<BR>&nbsp; StackTrace:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at IdeaBlade.EntityModel.EntityManager.HandleSaveResultException(SaveWorkState saveWorkState, Boolean isAsyncOp)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at IdeaBlade.EntityModel.EntityManager.SaveChangesCore(IEnumerable entities, SaveOptions saveOptions)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at IdeaBlade.EntityModel.EntityManager.SaveChanges(IEnumerable entities, SaveOptions saveOptions)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at IdeaBlade.EntityModel.EntityManager.SaveChanges()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at Microster.Maintenance.Views.OrgLevelSecurityPresenter.CreateOrganisationItemAccessEntity(HierarcialItem orgItem)<BR>&nbsp; InnerException: System.InvalidOperationException<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Message=The refresh attempt has failed because an unexpected entity was returned by the data source.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Source=System.Data.Entity<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; StackTrace:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at System.Data.Objects.ObjectContext.BatchRefreshEntitiesByKey(RefreshMode refreshMode, Dictionary`2 trackedEntities, EntitySet targetSet, List`1 targetKeys, Int32 startFrom)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at System.Data.Objects.ObjectContext.RefreshEntities(RefreshMode refreshMode, IEnumerable collection)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at System.Data.Objects.ObjectContext.Refresh(RefreshMode refreshMode, IEnumerable collection)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at IdeaBlade.EntityModel.Edm.EdmSaveHelper.RefreshEntities(IEnumerable`1 groupsByType)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at IdeaBlade.EntityModel.Edm.EdmSaveHelper.SaveWithinContext()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at IdeaBlade.EntityModel.Edm.EdmSaveHelper.Save()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; InnerException: </DIV><DIV>&nbsp;</DIV><DIV>&nbsp;</DIV><DIV>Thanks</DIV><DIV>Nitin<BR></DIV>]]>
   </description>
   <pubDate>Mon, 24 May 2010 19:06:36 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1842&amp;PID=7011#7011</guid>
  </item> 
 </channel>
</rss>