<?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 : Add and Remove</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : DevForce 2010 : Add and Remove</description>
  <pubDate>Wed, 29 Jul 2026 10:06:12 -700</pubDate>
  <lastBuildDate>Wed, 08 Dec 2010 12:43: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=2314</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>Add and Remove : I have been looking at the links...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2314&amp;PID=9330#9330</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=946" rel="nofollow">danjal</a><br /><strong>Subject:</strong> 2314<br /><strong>Posted:</strong> 08-Dec-2010 at 12:43pm<br /><br /><P style="MARGIN: 0cm 0cm 0pt" =Ms&#111;normal><FONT size=3><SPAN style="mso-ansi-: EN-US" lang=EN-US><FONT face=Calibri>I have been looking at the links regarding the concurrency issues – but I do not know what I am supposed to do </FONT></SPAN><SPAN style="FONT-FAMILY: Wingdings; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin; mso-symbol-font-family: Wingdings; mso-ansi-: EN-US; mso-char-: symbol" lang=EN-US><SPAN style="mso-symbol-font-family: Wingdings; mso-char-: symbol">J</SPAN></SPAN><SPAN style="mso-ansi-: EN-US" lang=EN-US><?: prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></FONT></P><P style="MARGIN: 0cm 0cm 0pt" =Ms&#111;normal><SPAN style="mso-ansi-: EN-US" lang=EN-US><FONT size=3><FONT face=Calibri>I am debugging the application up against a database that is only used by me – so there should not be any concurrency problems.<o:p></o:p></FONT></FONT></SPAN></P><P style="MARGIN: 0cm 0cm 0pt" =Ms&#111;normal><SPAN style="mso-ansi-: EN-US" lang=EN-US><o:p><FONT size=3 face=Calibri>&nbsp;</FONT></o:p></SPAN></P><P style="MARGIN: 0cm 0cm 0pt" =Ms&#111;normal><SPAN style="mso-ansi-: EN-US" lang=EN-US><FONT size=3><FONT face=Calibri>I have done something similar as described above, but where the many-to-many relations are in a table that has a “payload” and therefore exists as a type in my entity model. <B style="mso-bidi-font-weight: normal">This works fine</B>.<o:p></o:p></FONT></FONT></SPAN></P><P style="MARGIN: 0cm 0cm 0pt" =Ms&#111;normal><SPAN style="mso-ansi-: EN-US" lang=EN-US><FONT size=3><FONT face=Calibri>Here is my code for the add and remove methods, which work fine:<o:p></o:p></FONT></FONT></SPAN></P><P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: n&#111;ne" =Ms&#111;normal><SPAN style="FONT-FAMILY: C&#111;nsolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">protected</SPAN> <SPAN style="COLOR: blue">void</SPAN> OnRemoveGroup(<SPAN style="COLOR: #2b91af">EntPointGroupAccess</SPAN> newValue)<o:p></o:p></SPAN></P><P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: n&#111;ne" =Ms&#111;normal><SPAN style="FONT-FAMILY: C&#111;nsolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P><P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: n&#111;ne" =Ms&#111;normal><SPAN style="FONT-FAMILY: C&#111;nsolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>newValue.EntityAspect.Delete();<o:p></o:p></SPAN></P><P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: n&#111;ne" =Ms&#111;normal><SPAN style="FONT-FAMILY: C&#111;nsolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>p_groupsWithAccess = <SPAN style="COLOR: blue">null</SPAN>;<o:p></o:p></SPAN></P><P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: n&#111;ne" =Ms&#111;normal><SPAN style="FONT-FAMILY: C&#111;nsolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P><P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: n&#111;ne" =Ms&#111;normal><SPAN style="FONT-FAMILY: C&#111;nsolas; FONT-SIZE: 9.5pt"><o:p>&nbsp;</o:p></SPAN></P><P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: n&#111;ne" =Ms&#111;normal><SPAN style="FONT-FAMILY: C&#111;nsolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">protected</SPAN> <SPAN style="COLOR: blue">void</SPAN> OnAddGroup(<SPAN style="COLOR: #2b91af">EntUser</SPAN> newValue)<o:p></o:p></SPAN></P><P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: n&#111;ne" =Ms&#111;normal><SPAN style="FONT-FAMILY: C&#111;nsolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P><P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: n&#111;ne" =Ms&#111;normal><SPAN style="FONT-FAMILY: C&#111;nsolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">var</SPAN> tmp = <SPAN style="COLOR: #2b91af">C2NetDomainModelEntityManager</SPAN>.DefaultManager.CreateEntity&lt;<SPAN style="COLOR: #2b91af">EntPointGroupAccess</SPAN>&gt;();<o:p></o:p></SPAN></P><P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: n&#111;ne" =Ms&#111;normal><SPAN style="FONT-FAMILY: C&#111;nsolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>tmp.p_userID = newValue.p_userID;<o:p></o:p></SPAN></P><P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: n&#111;ne" =Ms&#111;normal><SPAN style="FONT-FAMILY: C&#111;nsolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>tmp.p_customerID = m_pointGroup.p_customerID;<o:p></o:p></SPAN></P><P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: n&#111;ne" =Ms&#111;normal><SPAN style="FONT-FAMILY: C&#111;nsolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>tmp.p_pointGrID = m_pointGroup.p_pointGrID;<o:p></o:p></SPAN></P><P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: n&#111;ne" =Ms&#111;normal><SPAN style="FONT-FAMILY: C&#111;nsolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>tmp.p_readWrite = 3;<o:p></o:p></SPAN></P><P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: n&#111;ne" =Ms&#111;normal><SPAN style="FONT-FAMILY: C&#111;nsolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>tmp.EntityAspect.AddToManager();<o:p></o:p></SPAN></P><P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: n&#111;ne" =Ms&#111;normal><SPAN style="FONT-FAMILY: C&#111;nsolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>p_groupsWithAccess = <SPAN style="COLOR: blue">null</SPAN>;<o:p></o:p></SPAN></P><P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: n&#111;ne" =Ms&#111;normal><SPAN style="FONT-FAMILY: C&#111;nsolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P><P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: n&#111;ne" =Ms&#111;normal><SPAN style="FONT-FAMILY: C&#111;nsolas; FONT-SIZE: 9.5pt"><o:p>&nbsp;</o:p></SPAN></P><P style="MARGIN: 0cm 0cm 0pt" =Ms&#111;normal><SPAN style="mso-ansi-: EN-US" lang=EN-US><FONT size=3><FONT face=Calibri>I am now thinking of making the table that contains the many-to-many relations between users and groups, into a “payload” table has a workaround.<o:p></o:p></FONT></FONT></SPAN></P><P style="MARGIN: 0cm 0cm 0pt" =Ms&#111;normal><SPAN style="mso-ansi-: EN-US" lang=EN-US><o:p><FONT size=3 face=Calibri>&nbsp;</FONT></o:p></SPAN></P>]]>
   </description>
   <pubDate>Wed, 08 Dec 2010 12:43:16 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2314&amp;PID=9330#9330</guid>
  </item> 
  <item>
   <title>Add and Remove : Hi danjal,  Theconcurrencyexception...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2314&amp;PID=9193#9193</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> 2314<br /><strong>Posted:</strong> 22-Nov-2010 at 9:59am<br /><br />Hi danjal,<DIV>&nbsp;</DIV><DIV>The&nbsp;concurrency&nbsp;exception occurs because you are trying to save an entity that seems to be modified previously by another entity manager or client. (i.e. the value of the field "holding" the concurrency strategy in the datasource is not the same as the value in your entity when it was initially loaded from the datasource)</DIV><DIV>&nbsp;</DIV><DIV>If you are using cuncurrency strategy, you must handle these concurrency conflicts. (for instance, update your entity to the most current state, according to datasource, before making changes and saving)</DIV><DIV>&nbsp;</DIV><DIV>You can find more information on concurrency in our <a href="http://drc.ideablade.com/xwiki/bin/view/&#068;ocumentati&#111;n/Saving_C&#111;ncurrency#HDataSourceC&#111;ncurrency" target="_blank">DevForce Resource Center</A>. There is also an example located&nbsp;<a href="http://drc.ideablade.com/xwiki/bin/view/&#068;ocumentati&#111;n/Code_HandlingC&#111;ncurrencyC&#111;nflicts" target="_blank">here</A>.</DIV><DIV>&nbsp;</DIV><DIV>Silvio.</DIV>]]>
   </description>
   <pubDate>Mon, 22 Nov 2010 09:59:23 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2314&amp;PID=9193#9193</guid>
  </item> 
  <item>
   <title>Add and Remove : Thanx sbelini, I will look into...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2314&amp;PID=9181#9181</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=946" rel="nofollow">danjal</a><br /><strong>Subject:</strong> 2314<br /><strong>Posted:</strong> 21-Nov-2010 at 11:21am<br /><br /><P style="MARGIN: 0cm 0cm 0pt" =Ms&#111;normal><SPAN style="mso-ansi-: EN-US" lang=EN-US><FONT size=3><FONT face=Calibri>Thanx sbelini,<?: prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></FONT></FONT></SPAN></P><P style="MARGIN: 0cm 0cm 0pt" =Ms&#111;normal><SPAN style="mso-ansi-: EN-US" lang=EN-US><FONT size=3><FONT face=Calibri>I will look into this.<o:p></o:p></FONT></FONT></SPAN></P><P style="MARGIN: 0cm 0cm 0pt" =Ms&#111;normal><SPAN style="mso-ansi-: EN-US" lang=EN-US><o:p><FONT size=3 face=Calibri>&nbsp;</FONT></o:p></SPAN></P><P style="MARGIN: 0cm 0cm 0pt" =Ms&#111;normal><SPAN style="mso-ansi-: EN-US" lang=EN-US><FONT size=3><FONT face=Calibri>I have been reading this documentation regarding adding and removing in the collection:<o:p></o:p></FONT></FONT></SPAN></P><P style="MARGIN: 0cm 0cm 0pt" =Ms&#111;normal><SPAN style="mso-ansi-: EN-US" lang=EN-US><a href="http://drc.ideablade.com/xwiki/bin/view/&#068;ocumentati&#111;n/CreatingEntities#HAddingandRemovingRelated&#079;bjectsusingAdd2829andRemove2829" target="_blank"><U><FONT size=3 face=Calibri>http://drc.ideablade.com/xwiki/bin/view/Documentation/CreatingEntities#HAddingandRemovingRelatedObjectsusingAdd2829andRemove2829</FONT></U></A><o:p></o:p></SPAN></P><P style="MARGIN: 0cm 0cm 0pt" =Ms&#111;normal><SPAN style="mso-ansi-: EN-US" lang=EN-US><o:p><FONT size=3 face=Calibri>&nbsp;</FONT></o:p></SPAN></P><P style="MARGIN: 0cm 0cm 0pt" =Ms&#111;normal><SPAN style="mso-ansi-: EN-US" lang=EN-US><FONT size=3><FONT face=Calibri>As I say, it works to add to the collection, but I get an exception when removing and saving. <B style="mso-bidi-font-weight: normal">Why do I get this exception?</B><o:p></o:p></FONT></FONT></SPAN></P><P style="MARGIN: 0cm 0cm 0pt" =Ms&#111;normal><SPAN style="mso-ansi-: EN-US" lang=EN-US><o:p><FONT size=3 face=Calibri>&nbsp;</FONT></o:p></SPAN></P><P style="MARGIN: 0cm 0cm 0pt" =Ms&#111;normal><SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Verdana','sans-serif'; COLOR: red; FONT-SIZE: 8pt; mso-ansi-: EN-US" lang=EN-US>Entity Save Error: System.Data.OptimisticConcurrencyException: Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries. at System.Data.Mapping.Update.Internal.UpdateTranslator.ValidateRowsAffected(Int64 rowsAffected, UpdateCommand source) at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter) at System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache) at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options) at IdeaBlade.EntityModel.Edm.EdmSaveExecutor.ProcessSaves(IEnumerable`1 groupsByType) at IdeaBlade.EntityModel.Edm.EdmSaveExecutor.SaveWithinContext() at IdeaBlade.EntityModel.Edm.EdmSaveExecutor.Save(DataSourceResolver dataSourceResolver, IDataSourceKey dsKey, SaveWorkState workState)</SPAN><SPAN style="COLOR: red; mso-ansi-: EN-US" lang=EN-US><o:p></o:p></SPAN></P>]]>
   </description>
   <pubDate>Sun, 21 Nov 2010 11:21:26 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2314&amp;PID=9181#9181</guid>
  </item> 
  <item>
   <title>Add and Remove : Hi danjal, Changes to collections...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2314&amp;PID=9178#9178</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> 2314<br /><strong>Posted:</strong> 19-Nov-2010 at 5:46pm<br /><br /><P>Hi danjal,</P><DIV>Changes to collections related to an entity don't cause the entity to be changed&nbsp;because no field on the entity is itself changing.</DIV><DIV>For instance, in a one to many relashionship Customer_Order if you do:</DIV><DIV>&nbsp;</DIV><DIV><FONT size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas>aCustomer.Orders.Add(anOrder);</FONT></FONT></DIV><DIV>&nbsp;</DIV><DIV>aCustomer will keep the entity aspect as Unchanged, while anOrder will be set to Modified since the&nbsp;FK, which is a scalar property, (CustomerID) was changed.</DIV><DIV>&nbsp;</DIV><DIV>In this case, instead of manually changing EntityState to trigger an event, you should be watching the CollectionChanged event:</DIV><DIV><FONT size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas></FONT></FONT>&nbsp;</DIV><DIV><FONT face=C&#111;nsolas><FONT face=C&#111;nsolas><FONT size=2>p_currentUser.p_userGroups.CollectionChanged += (s, e) =&gt; {</FONT></DIV><DIV><DIV></FONT></FONT><FONT color=#0000ff size=2 face=C&#111;nsolas><FONT color=#0000ff size=2 face=C&#111;nsolas><FONT color=#0000ff size=2 face=C&#111;nsolas>&nbsp; if</FONT></FONT></FONT><FONT size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas> (e.Action == </FONT></FONT><FONT color=#2b91af size=2 face=C&#111;nsolas><FONT color=#2b91af size=2 face=C&#111;nsolas><FONT color=#2b91af size=2 face=C&#111;nsolas>NotifyCollectionChangedAction</FONT></FONT></FONT><FONT size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas>.Add) {</FONT></FONT></DIV><DIV><FONT size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas><FONT color=#008000 size=2 face=C&#111;nsolas><FONT color=#008000 size=2 face=C&#111;nsolas><FONT color=#008000 size=2 face=C&#111;nsolas>&nbsp; &nbsp; // Do something</DIV><DIV></FONT></FONT></FONT></FONT></FONT><FONT size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas>&nbsp; } </FONT></FONT><FONT color=#0000ff size=2 face=C&#111;nsolas><FONT color=#0000ff size=2 face=C&#111;nsolas><FONT color=#0000ff size=2 face=C&#111;nsolas>else</FONT></FONT></FONT><FONT size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas> </FONT></FONT><FONT color=#0000ff size=2 face=C&#111;nsolas><FONT color=#0000ff size=2 face=C&#111;nsolas><FONT color=#0000ff size=2 face=C&#111;nsolas>if</FONT></FONT></FONT><FONT size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas> (e.Action == </FONT></FONT><FONT color=#2b91af size=2 face=C&#111;nsolas><FONT color=#2b91af size=2 face=C&#111;nsolas><FONT color=#2b91af size=2 face=C&#111;nsolas>NotifyCollectionChangedAction</FONT></FONT></FONT><FONT size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas>.Remove) {</FONT></FONT></DIV><DIV><FONT color=#0000ff size=2 face=C&#111;nsolas><FONT color=#0000ff size=2 face=C&#111;nsolas><FONT color=#0000ff size=2 face=C&#111;nsolas><FONT color=#008000 size=2 face=C&#111;nsolas><FONT color=#008000 size=2 face=C&#111;nsolas><FONT color=#008000 size=2 face=C&#111;nsolas>&nbsp; &nbsp; // Do something</DIV><DIV><DIV></FONT></FONT></FONT></FONT></FONT></FONT><FONT size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas>&nbsp; }</DIV></DIV><DIV>};</DIV><DIV>&nbsp;</DIV><DIV></FONT></FONT>&nbsp;</DIV></DIV><DIV>Regards,</DIV><DIV>&nbsp;&nbsp; sbelini.</DIV>]]>
   </description>
   <pubDate>Fri, 19 Nov 2010 17:46:50 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2314&amp;PID=9178#9178</guid>
  </item> 
  <item>
   <title>Add and Remove : We have a database table called...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2314&amp;PID=9142#9142</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=946" rel="nofollow">danjal</a><br /><strong>Subject:</strong> 2314<br /><strong>Posted:</strong> 17-Nov-2010 at 4:08am<br /><br /><P style="MARGIN: 0cm 0cm 0pt" ="Ms&#111;normal"><SPAN style="mso-ansi-: EN-US" lang=EN-US><FONT size=3><FONT face=Calibri>We have a database table called <B style="mso-bidi-font-weight: normal">EntUser</B>.<?: prefix = o ns = "urn:schemas-microsoft-com:office:office" /><O:P></O:P></FONT></FONT></SPAN></P><P style="MARGIN: 0cm 0cm 0pt" ="Ms&#111;normal"><SPAN style="mso-ansi-: EN-US" lang=EN-US><FONT size=3><FONT face=Calibri>The table contains, among others, the fields: <B style="mso-bidi-font-weight: normal">p_userID</B> and <B style="mso-bidi-font-weight: normal">p_isGroup</B>.<O:P></O:P></FONT></FONT></SPAN></P><P style="MARGIN: 0cm 0cm 0pt" ="Ms&#111;normal"><SPAN style="mso-ansi-: EN-US" lang=EN-US><FONT size=3><FONT face=Calibri>The table contains our users and groups, <B style="mso-bidi-font-weight: normal">and p_isGroup</B> determines whether the entity is a user or group.<O:P></O:P></FONT></FONT></SPAN></P><P style="MARGIN: 0cm 0cm 0pt" ="Ms&#111;normal"><SPAN style="mso-ansi-: EN-US" lang=EN-US><O:P><FONT size=3 face=Calibri>&nbsp;</FONT></O:P></SPAN></P><P style="MARGIN: 0cm 0cm 0pt" ="Ms&#111;normal"><SPAN style="mso-ansi-: EN-US" lang=EN-US><FONT size=3><FONT face=Calibri>What users that are in what groups is determined in an second table called <B style="mso-bidi-font-weight: normal">EntUserGroups</B>.<O:P></O:P></FONT></FONT></SPAN></P><P style="MARGIN: 0cm 0cm 0pt" ="Ms&#111;normal"><SPAN style="mso-ansi-: EN-US" lang=EN-US><FONT size=3><FONT face=Calibri>This table has two fields: <B style="mso-bidi-font-weight: normal">p_userID</B> and <B style="mso-bidi-font-weight: normal">p_groupID</B><O:P></O:P></FONT></FONT></SPAN></P><P style="MARGIN: 0cm 0cm 0pt" ="Ms&#111;normal"><SPAN style="mso-ansi-: EN-US" lang=EN-US><O:P><FONT size=3 face=Calibri>&nbsp;</FONT></O:P></SPAN></P><P style="MARGIN: 0cm 0cm 0pt" ="Ms&#111;normal"><SPAN style="mso-ansi-: EN-US" lang=EN-US><FONT size=3><FONT face=Calibri>Ideablade Entity model gives us the opportunity to see what groups a user is in by this statement:<O:P></O:P></FONT></FONT></SPAN></P><P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: n&#111;ne" ="Ms&#111;normal"><SPAN style="FONT-FAMILY: C&#111;nsolas; FONT-SIZE: 9.5pt">p_currentUser.p_userGroups;<O:P></O:P></SPAN></P><P style="MARGIN: 0cm 0cm 0pt" ="Ms&#111;normal"><SPAN style="mso-ansi-: EN-US" lang=EN-US><O:P><FONT size=3 face=Calibri>&nbsp;</FONT></O:P></SPAN></P><P style="MARGIN: 0cm 0cm 0pt" ="Ms&#111;normal"><SPAN style="mso-ansi-: EN-US" lang=EN-US><FONT size=3><FONT face=Calibri>And what users that are in a group:<O:P></O:P></FONT></FONT></SPAN></P><P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: n&#111;ne" ="Ms&#111;normal"><SPAN style="FONT-FAMILY: C&#111;nsolas; FONT-SIZE: 9.5pt">p_currentGroup.p_users;<O:P></O:P></SPAN></P><P style="MARGIN: 0cm 0cm 0pt" ="Ms&#111;normal"><O:P><FONT size=3 face=Calibri></P><DIV><P style="MARGIN: 0cm 0cm 0pt" =Ms&#111;normal><?: prefix = o ns = "urn:schemas-microsoft-com:office:office" /><O:P>&nbsp;</O:P></P><P style="MARGIN: 0cm 0cm 0pt" =Ms&#111;normal><SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: C&#111;nsolas; COLOR: black; FONT-SIZE: 9.5pt; mso-fareast-font-family: 'Times New Roman'; mso-fareast-: IS; mso-ansi-: EN" lang=EN>p_currentUser</SPAN> and <SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: C&#111;nsolas; COLOR: black; FONT-SIZE: 9.5pt; mso-fareast-font-family: 'Times New Roman'; mso-fareast-: IS; mso-ansi-: EN" lang=EN>p_currentGroup</SPAN> are of type <B style="mso-bidi-font-weight: normal">EntUser</B>.<O:P></O:P></P><P style="MARGIN: 0cm 0cm 0pt" =Ms&#111;normal><SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: C&#111;nsolas; COLOR: black; FONT-SIZE: 9.5pt; mso-fareast-font-family: 'Times New Roman'; mso-fareast-: IS; mso-ansi-: EN" lang=EN>P_userGroups</SPAN> and <SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: C&#111;nsolas; COLOR: black; FONT-SIZE: 9.5pt; mso-fareast-font-family: 'Times New Roman'; mso-fareast-: IS; mso-ansi-: EN" lang=EN>p_users</SPAN> are of type <B style="mso-bidi-font-weight: normal">IdeaBlade.EntityModel.RelatedEntityList&lt;EntUser&gt;</B><O:P></O:P></P><P style="MARGIN: 0cm 0cm 0pt" =Ms&#111;normal><O:P>&nbsp;</O:P></P></FONT></O:P></DIV><P style="MARGIN: 0cm 0cm 0pt" ="Ms&#111;normal"><SPAN style="mso-ansi-: EN-US" lang=EN-US><FONT size=3><FONT face=Calibri>On my UI, I have two ListBoxes: one shows all groups and the second shows the groups that a current user is in. Between these ListBoxes are two buttons: Add and Remove.<O:P></O:P></FONT></FONT></SPAN></P><P style="MARGIN: 0cm 0cm 0pt" ="Ms&#111;normal"><SPAN style="mso-ansi-: EN-US" lang=EN-US><FONT size=3><FONT face=Calibri>When I add or remove a group to/from the current users groups, a Save button shall become enabled – this works fine by looking at the <B style="mso-bidi-font-weight: normal">entitymanager.EntityChanged</B> event.<O:P></O:P></FONT></FONT></SPAN></P><P style="MARGIN: 0cm 0cm 0pt" ="Ms&#111;normal"><SPAN style="mso-ansi-: EN-US" lang=EN-US><O:P><FONT size=3 face=Calibri>&nbsp;</FONT></O:P></SPAN></P><P style="MARGIN: 0cm 0cm 0pt" ="Ms&#111;normal"><SPAN style="mso-ansi-: EN-US" lang=EN-US><FONT size=3><FONT face=Calibri>The code behind the Add button looks something like this:<O:P></O:P></FONT></FONT></SPAN></P><P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: n&#111;ne" ="Ms&#111;normal"><SPAN style="FONT-FAMILY: C&#111;nsolas; COLOR: blue; FONT-SIZE: 9.5pt">protected</SPAN><SPAN style="FONT-FAMILY: C&#111;nsolas; FONT-SIZE: 9.5pt"> <SPAN style="COLOR: blue">void</SPAN> OnAddGroup(<SPAN style="COLOR: #2b91af">EntUser</SPAN> newValue)<O:P></O:P></SPAN></P><P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: n&#111;ne" ="Ms&#111;normal"><SPAN style="FONT-FAMILY: C&#111;nsolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<O:P></O:P></SPAN></P><P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: n&#111;ne" ="Ms&#111;normal"><SPAN style="FONT-FAMILY: C&#111;nsolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>p_currentUser.p_userGroups.Add(newValue);<O:P></O:P></SPAN></P><P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: n&#111;ne" ="Ms&#111;normal"><SPAN style="FONT-FAMILY: C&#111;nsolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>p_currentUser.EntityAspect.SetModified();<O:P></O:P></SPAN></P><P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: n&#111;ne" ="Ms&#111;normal"><SPAN style="FONT-FAMILY: C&#111;nsolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<O:P></O:P></SPAN></P><P style="MARGIN: 0cm 0cm 0pt" ="Ms&#111;normal"><SPAN style="mso-ansi-: EN-US" lang=EN-US><O:P><FONT size=3 face=Calibri>&nbsp;</FONT></O:P></SPAN></P><P style="MARGIN: 0cm 0cm 0pt" ="Ms&#111;normal"><SPAN style="mso-ansi-: EN-US" lang=EN-US><FONT size=3><FONT face=Calibri>This works fine, but I have to use SetModified to trigger the entitymanager.EntityChanged event.<O:P></O:P></FONT></FONT></SPAN></P><P style="MARGIN: 0cm 0cm 0pt" ="Ms&#111;normal"><B style="mso-bidi-font-weight: normal"><SPAN style="mso-ansi-: EN-US" lang=EN-US><FONT size=3><FONT face=Calibri>My question here: is this the right way to do this?<O:P></O:P></FONT></FONT></SPAN></B></P><P style="MARGIN: 0cm 0cm 0pt" ="Ms&#111;normal"><SPAN style="mso-ansi-: EN-US" lang=EN-US><O:P><FONT size=3 face=Calibri>&nbsp;</FONT></O:P></SPAN></P><P style="MARGIN: 0cm 0cm 0pt" ="Ms&#111;normal"><SPAN style="mso-ansi-: EN-US" lang=EN-US><FONT size=3><FONT face=Calibri>The code behind the Remove button looks something like this:<O:P></O:P></FONT></FONT></SPAN></P><P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: n&#111;ne" ="Ms&#111;normal"><SPAN style="FONT-FAMILY: C&#111;nsolas; COLOR: blue; FONT-SIZE: 9.5pt">protected</SPAN><SPAN style="FONT-FAMILY: C&#111;nsolas; FONT-SIZE: 9.5pt"> <SPAN style="COLOR: blue">void</SPAN> OnRemoveGroup(<SPAN style="COLOR: #2b91af">EntUser</SPAN> newValue)<O:P></O:P></SPAN></P><P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: n&#111;ne" ="Ms&#111;normal"><SPAN style="FONT-FAMILY: C&#111;nsolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<O:P></O:P></SPAN></P><P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: n&#111;ne" ="Ms&#111;normal"><SPAN style="FONT-FAMILY: C&#111;nsolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;</SPAN>p_currentUser.p_userGroups.Remove(newValue);<O:P></O:P></SPAN></P><P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: n&#111;ne" ="Ms&#111;normal"><SPAN style="FONT-FAMILY: C&#111;nsolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>p_currentUser.EntityAspect.SetModified();<O:P></O:P></SPAN></P><P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: n&#111;ne" ="Ms&#111;normal"><SPAN style="FONT-FAMILY: C&#111;nsolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<O:P></O:P></SPAN></P><P style="MARGIN: 0cm 0cm 0pt" ="Ms&#111;normal"><SPAN style="mso-ansi-: EN-US" lang=EN-US><O:P><FONT size=3 face=Calibri>&nbsp;</FONT></O:P></SPAN></P><P style="MARGIN: 0cm 0cm 0pt" ="Ms&#111;normal"><SPAN style="mso-ansi-: EN-US" lang=EN-US><FONT size=3><FONT face=Calibri>This does not remove the group from p_userGroups. I get this exception when I save:</P><DIV><SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Verdana', 'sans-serif'; FONT-SIZE: 8pt; mso-ansi-: EN-US; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-fareast-: IS" lang=EN-US>Entity Save Error: System.Data.OptimisticConcurrencyException: Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries. at System.Data.Mapping.Update.Internal.UpdateTranslator.ValidateRowsAffected(Int64 rowsAffected, UpdateCommand source) at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter) at System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache) at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options) at IdeaBlade.EntityModel.Edm.EdmSaveExecutor.ProcessSaves(IEnumerable`1 groupsByType) at IdeaBlade.EntityModel.Edm.EdmSaveExecutor.SaveWithinContext() at IdeaBlade.EntityModel.Edm.EdmSaveExecutor.Save(DataSourceResolver dataSourceResolver, IDataSourceKey dsKey, SaveWorkState workState)<P style="MARGIN: 0cm 0cm 0pt" =Ms&#111;normal><O:P><FONT size=3 face=Calibri>&nbsp;</FONT></O:P></P></SPAN></DIV><O:P></O:P><O:P></O:P></FONT></FONT></SPAN><SPAN style="mso-ansi-: EN-US" lang=EN-US><FONT size=3><FONT face=Calibri><DIV>I then changed my Remove method to something like this:<O:P></O:P></FONT></FONT></SPAN></DIV><P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: n&#111;ne" ="Ms&#111;normal"><SPAN style="FONT-FAMILY: C&#111;nsolas; COLOR: blue; FONT-SIZE: 9.5pt">protected</SPAN><SPAN style="FONT-FAMILY: C&#111;nsolas; FONT-SIZE: 9.5pt"> <SPAN style="COLOR: blue">void</SPAN> OnRemoveGroup(<SPAN style="COLOR: #2b91af">EntUser</SPAN> newValue)<O:P></O:P></SPAN></P><P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: n&#111;ne" ="Ms&#111;normal"><SPAN style="FONT-FAMILY: C&#111;nsolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<O:P></O:P></SPAN></P><P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: n&#111;ne" ="Ms&#111;normal"><SPAN style="FONT-FAMILY: C&#111;nsolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">var</SPAN> i = p_currentUser.p_userGroups.IndexOf(newValue);<O:P></O:P></SPAN></P><P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: n&#111;ne" ="Ms&#111;normal"><SPAN style="FONT-FAMILY: C&#111;nsolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>p_currentUser.p_userGroups i&nbsp;<EM><EM><EM><EM><EM><EM><EM>.EntityAspect.Delete();<O:P></O:P></SPAN></P><P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: n&#111;ne" ="Ms&#111;normal"><SPAN style="FONT-FAMILY: C&#111;nsolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>updateGroupIdsForUser();<O:P></O:P></SPAN></P><P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: n&#111;ne" ="Ms&#111;normal"><SPAN style="FONT-FAMILY: C&#111;nsolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<O:P></O:P></SPAN></P><P style="MARGIN: 0cm 0cm 0pt" ="Ms&#111;normal"><SPAN style="mso-ansi-: EN-US" lang=EN-US><O:P><FONT size=3 face=Calibri>&nbsp;</FONT></O:P></SPAN></P><P style="MARGIN: 0cm 0cm 0pt" ="Ms&#111;normal"><FONT size=3><SPAN style="mso-ansi-: EN-US" lang=EN-US><FONT face=Calibri>But this actually deletes the group from the <B style="mso-bidi-font-weight: normal">EntUser</B> database table </FONT></SPAN><SPAN style="FONT-FAMILY: Wingdings; mso-ansi-: EN-US; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin; mso-char-: symbol; mso-symbol-font-family: Wingdings" lang=EN-US><SPAN style="mso-char-: symbol; mso-symbol-font-family: Wingdings">J</SPAN></SPAN><SPAN style="mso-ansi-: EN-US" lang=EN-US><O:P></O:P></SPAN></FONT></P><P style="MARGIN: 0cm 0cm 0pt" ="Ms&#111;normal"><B style="mso-bidi-font-weight: normal"><SPAN style="mso-ansi-: EN-US" lang=EN-US><FONT size=3><FONT face=Calibri>My question here: how do I remove a group from p_userGroups and save the changes? </P><DIV><SPAN style="mso-ansi-: EN-US" lang=EN-US><?: PREFIX = O /><O:P><FONT size=3 face=Calibri></FONT></O:P></SPAN>&nbsp;</DIV></FONT></FONT></SPAN></B></EM></EM></EM></EM></EM></EM></EM><span style="font-size:10px"><br /><br />Edited by danjal - 19-Nov-2010 at 2:28am</span>]]>
   </description>
   <pubDate>Wed, 17 Nov 2010 04:08:37 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2314&amp;PID=9142#9142</guid>
  </item> 
 </channel>
</rss>