<?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 : Save entity thows me InvalidOperationException</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : DevForce 2010 : Save entity thows me InvalidOperationException</description>
  <pubDate>Wed, 13 May 2026 04:40:34 -700</pubDate>
  <lastBuildDate>Tue, 10 Jul 2012 08:37:18 -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=3528</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>Save entity thows me InvalidOperationException :   Hi Paolo,I wouldn&amp;#039;t be...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3528&amp;PID=13991#13991</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> 3528<br /><strong>Posted:</strong> 10-Jul-2012 at 8:37am<br /><br />Hi Paolo,<div>&nbsp;</div><div>I wouldn't be able to simply tell you what to improve without understanding the goal in dept.</div><div>&nbsp;</div><div>We have a Professional Services team that would be able to better assist you in your task. </div><div>Please let me know if you would like to be contacted by them.</div><div>&nbsp;</div><div>Regards, </div><div>&nbsp;&nbsp; Silvio.</div>]]>
   </description>
   <pubDate>Tue, 10 Jul 2012 08:37:18 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3528&amp;PID=13991#13991</guid>
  </item> 
  <item>
   <title>Save entity thows me InvalidOperationException :   Hello Silvio.....I&amp;#039;ve...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3528&amp;PID=13990#13990</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1136" rel="nofollow">pponzano</a><br /><strong>Subject:</strong> 3528<br /><strong>Posted:</strong> 10-Jul-2012 at 2:45am<br /><br />Hello Silvio.....I've almost managed but I really don't like this...hope you can give me guidelines to improve my code...<div>&nbsp;</div><div>He'res the EndEdit method that will do the process</div><div>&nbsp;</div><div><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;"><span style="color: blue;">public</span> <span style="color: rgb43, 145, 175;">IEnumerable</span>&lt;<span style="color: rgb43, 145, 175;">IResult</span>&gt; EndEdit(<span style="color: blue;">object</span> sender, <span style="color: rgb43, 145, 175;">EditEndedEventArgs</span> e)</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;&nbsp;&nbsp; &nbsp; {</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; <span style="color: blue;">switch</span> (e.EditAction)</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; {</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; <span style="color: blue;">case</span> Telerik.Windows.Controls.Data.DataForm.<span style="color: rgb43, 145, 175;">EditAction</span>.Cancel:</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; repository.RejectChangesAsync();</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; <span style="color: blue;">break</span>;</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; <span style="color: blue;">case</span> Telerik.Windows.Controls.Data.DataForm.<span style="color: rgb43, 145, 175;">EditAction</span>.Commit:</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; <span style="color: blue;">var</span> script = (sender <span style="color: blue;">as</span> <span style="color: rgb43, 145, 175;">RadDataForm</span>).CurrentItem <span style="color: blue;">as</span> <span style="color: rgb43, 145, 175;">SCRIPT</span>;</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; <span style="color: rgb43, 145, 175;">OperationResult</span> operation;</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; <span style="color: blue;">var</span> checkedItems = ListaVariabiliExt.Where(o1=&gt;o1.IsChecked);</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; <span style="color: blue;">yield</span> <span style="color: blue;">return</span> (operation = repository.DeleteOldRelationsScriptVariabili(script, SelectedDataItem.SCRIPT_VARIABILI));</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; <span style="color: blue;">if</span> (operation.CompletedSuccessfully)</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; {</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; <span style="color: blue;">yield</span> <span style="color: blue;">return</span> (operation = repository.SaveAsync());</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; <span style="color: blue;">if</span> (operation.CompletedSuccessfully)</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; {</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; <span style="color: blue;">yield</span> <span style="color: blue;">return</span> (operation = repository.UpdateScript(script, checkedItems));</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; <span style="color: blue;">if</span> (operation.CompletedSuccessfully)</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; {</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; <span style="color: blue;">yield</span> <span style="color: blue;">return</span> (operation = repository.SaveAsync());</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; }</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; }</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; }</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; <span style="color: blue;">if</span> (operation.HasError)</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; {</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; <span style="color: green;">//todo : add logging</span></p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; }</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; <span style="color: blue;">break</span>;</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; <span style="color: blue;">default</span>:</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; <span style="color: blue;">throw</span> <span style="color: blue;">new</span> <span style="color: rgb43, 145, 175;">InvalidOperationException</span>(<span style="color: rgb163, 21, 21;">"Edit action should be Cancel or Commit only."</span>);</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; }</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; IsEditing = <span style="color: blue;">false</span>;</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; <span style="color: blue;">yield</span> <span style="color: blue;">break</span>;</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;">&nbsp;&nbsp;&nbsp; &nbsp; }</p><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div></div><div><font size="2" face="C&#111;nsolas">And here's the repository implementation</font></div><div><font size="2" face="C&#111;nsolas"></font>&nbsp;</div><div><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><span style="color: blue;"><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"><pre style="margin: 0px;"><span style="color: blue;">public</span> <span style="color: rgb43, 145, 175;">OperationResult</span> UpdateScript(<span style="color: rgb43, 145, 175;">SCRIPT</span> script, <span style="color: rgb43, 145, 175;">IEnumerable</span>&lt;<span style="color: rgb43, 145, 175;">VARIABILI</span>&gt; variabili, <span style="color: rgb43, 145, 175;">Action</span>&lt;<span style="color: rgb43, 145, 175;">IEnumerable</span>&gt; onSuccess = <span style="color: blue;">null</span>, <span style="color: rgb43, 145, 175;">Action</span>&lt;<span style="color: rgb43, 145, 175;">Exception</span>&gt; onFail = <span style="color: blue;">null</span>)</pre><pre style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; {</pre><pre style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; entityManagerProvider.Manager.AddEntity(script);</pre><pre style="margin: 0px;">&nbsp;</pre><pre style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; <span style="color: blue;">if</span> (variabili.Any())</pre><pre style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; {</pre><pre style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; variabili.ForEach((item) =&gt;</pre><pre style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; {</pre><pre style="margin: 0px;">&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; <span style="color: blue;">var</span> scriptVariabili = entityManagerProvider.Manager.CreateEntity&lt;<span style="color: rgb43, 145, 175;">SCRIPT_VARIABILI</span>&gt;();</pre><pre style="margin: 0px;">&nbsp;</pre><pre style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; scriptVariabili.ID_SCRIPT = script.ID;</pre><pre style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; scriptVariabili.ID_VARIABILE = item.ID;</pre><pre style="margin: 0px;">&nbsp;</pre><pre style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; entityManagerProvider.Manager.AddEntity(scriptVariabili);</pre><pre style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; });</pre><pre style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; }</pre><pre style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; <span style="color: blue;">return</span> <span style="color: rgb43, 145, 175;">AlwaysCompletedOperationResult</span>.Instance;</pre><pre style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; }</pre><pre style="margin: 0px;">&nbsp;</pre><pre style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: rgb43, 145, 175;">OperationResult</span> DeleteOldRelationsScriptVariabili(<span style="color: rgb43, 145, 175;">SCRIPT</span> script, <span style="color: rgb43, 145, 175;">RelatedEntityList</span>&lt;<span style="color: rgb43, 145, 175;">SCRIPT_VARIABILI</span>&gt; variabili, <span style="color: rgb43, 145, 175;">Action</span>&lt;<span style="color: rgb43, 145, 175;">IEnumerable</span>&gt; onSuccess = <span style="color: blue;">null</span>, <span style="color: rgb43, 145, 175;">Action</span>&lt;<span style="color: rgb43, 145, 175;">Exception</span>&gt; onFail = <span style="color: blue;">null</span>)</pre><pre style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; {</pre><pre style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; <span style="color: blue;">if</span> (variabili.Any())</pre><pre style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; {</pre><pre style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; <span style="color: blue;">for</span> (<span style="color: blue;">int</span> i = variabili.Count - 1; i &gt;= 0; i--)</pre><pre style="margin: 0px;">&nbsp;</pre><pre style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; variabili<em>.EntityAspect.Delete();</pre><pre style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; }</pre><pre style="margin: 0px;">&nbsp;</pre><pre style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; <span style="color: blue;">return</span> <span style="color: rgb43, 145, 175;">AlwaysCompletedOperationResult</span>.Instance;</pre><pre style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; }</pre></div><p style=": white; margin: 0px; color: black; font-family: C&#111;nsolas; font-size: 10pt;"><!--EndFragment--></p><div>How can I improve this? all those nested yield return are not so good for me... and even for maintenability...</div><div>Thanks</span></div></div><div><!--EndFragment--></div><div style=": white; color: black; font-family: C&#111;nsolas; font-size: 10pt;"></div><div><!--EndFragment--></div>]]>
   </description>
   <pubDate>Tue, 10 Jul 2012 02:45:05 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3528&amp;PID=13990#13990</guid>
  </item> 
  <item>
   <title>Save entity thows me InvalidOperationException : So what you suggest me to do Silvio?  ...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3528&amp;PID=13989#13989</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1136" rel="nofollow">pponzano</a><br /><strong>Subject:</strong> 3528<br /><strong>Posted:</strong> 09-Jul-2012 at 10:29pm<br /><br />So what you suggest me to do Silvio?]]>
   </description>
   <pubDate>Mon, 09 Jul 2012 22:29:05 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3528&amp;PID=13989#13989</guid>
  </item> 
  <item>
   <title>Save entity thows me InvalidOperationException :   Hi Paolo,Calling script.SCRIPT_VARIABILI.Clear();will...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3528&amp;PID=13982#13982</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> 3528<br /><strong>Posted:</strong> 09-Jul-2012 at 12:12pm<br /><br />Hi Paolo,<div>&nbsp;</div><div>Calling </div><div>script.SCRIPT_VARIABILI.Clear();</div><div>will not remove your scriptVariabili from the entity cache nor will it update their FK. (in your case the composite PK)</div><div>&nbsp;</div><div>Also, you should be using AddEntity instead of AttachEntity.</div><div>&nbsp;</div><div>Another thing to be aware of is that even if you delete a scriptVariabile and create a new one with the same Id, you will have the "<em>An entity with this key: SCRIPT_VARIABILI: 1,0 already exists in this EntityManager</em>" error message if both delete (of the old entity) and save (of the new entity) operations are performed in the same entityManager.SaveCh;anges call.</div><div>&nbsp;</div><div>&nbsp;</div><div>Regards,</div><div>&nbsp;&nbsp; Silvio.</div><div>&nbsp;</div>]]>
   </description>
   <pubDate>Mon, 09 Jul 2012 12:12:59 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3528&amp;PID=13982#13982</guid>
  </item> 
  <item>
   <title>Save entity thows me InvalidOperationException : Hello,I&amp;#039;ve been facing this...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3528&amp;PID=13980#13980</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1136" rel="nofollow">pponzano</a><br /><strong>Subject:</strong> 3528<br /><strong>Posted:</strong> 09-Jul-2012 at 7:59am<br /><br />Hello,<br>I've been facing this all day long... I cannot succed... <br><br>I've got an entity with n...m relation<br><br>Consider a Script table<br>a Variable Table<br>and a Script_Variable table (id_script int, id_variable int)<br><br>I've defined this UpdateScript inside my repository that does<br><br><div style="font-family: C&#111;nsolas; font-size: 10pt; color: black; : white;"><p style="margin: 0px;"><span style="color: blue;">public</span> <span style="color: #2b91af;">OperationResult</span> UpdateScript(<span style="color: #2b91af;">SCRIPT</span> script, <span style="color: #2b91af;">IEnumerable</span>&lt;<span style="color: #2b91af;">VARIABILI</span>&gt; variabili, <span style="color: #2b91af;">Action</span>&lt;<span style="color: #2b91af;">IEnumerable</span>&gt; onSuccess = <span style="color: blue;">null</span>, <span style="color: #2b91af;">Action</span>&lt;<span style="color: #2b91af;">Exception</span>&gt; onFail = <span style="color: blue;">null</span>)</p><p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; {</p><p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; entityManagerProvider.Manager.AttachEntity(script);</p><p style="margin: 0px;">&nbsp;</p><p style="margin: 0px;">&nbsp;</p><p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; script.SCRIPT_VARIABILI.Clear();</p><p style="margin: 0px;">&nbsp;</p><p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; <span style="color: blue;">if</span> (variabili.Any())</p><p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; {</p><p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; variabili.ForEach((item) =&gt;</p><p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; {</p><p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; <span style="color: blue;">var</span> scriptVariabili = entityManagerProvider.Manager.CreateEntity&lt;<span style="color: #2b91af;">SCRIPT_VARIABILI</span>&gt;();</p><p style="margin: 0px;">&nbsp;</p><p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; scriptVariabili.ID_SCRIPT = script.ID;</p><p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; scriptVariabili.ID_VARIABILE = item.ID;</p><p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; entityManagerProvider.Manager.AttachEntity(scriptVariabili);</p><p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; });</p><p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; }</p><p style="margin: 0px;">&nbsp;</p><p style="margin: 0px;">&nbsp;</p><p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; <span style="color: blue;">return</span> <span style="color: #2b91af;">AlwaysCompletedOperationResult</span>.Instance;</p><p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; }</p></div><br>I got this exception<br><br>An entity with this key: SCRIPT_VARIABILI: 1,0 already exists in this EntityManager on &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; entityManagerProvider.Manager.AttachEntity(scriptVariabili);<br><br>I tougth that the script.SCRIPT_VARIABILI.Clear() would have removed all my pre-esistent items but it doesn't seem so... what am I doing wrong?<br><br>Thanks<br><br>]]>
   </description>
   <pubDate>Mon, 09 Jul 2012 07:59:56 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3528&amp;PID=13980#13980</guid>
  </item> 
 </channel>
</rss>