Ticket T587005
Visible to All Users
Duplicate

We have closed this ticket because another page addresses its subject:

Core - An exception is thrown when a link is added to many-to-many collections in different ObjectSpaces

"Duplicate key" error trying to save roles and users

created 7 years ago

Hi,

I have the following scenario:

  1. User goes to Roles screen. He selects a specific role to edit. Let's say that he selects "Administrators" role.
  2. Editing the role "Administrators" that user clicks the "New" button of the "Users" tab.
  3. Adding a new user, that person clicks the option "Link" of the "Roles" tab and selects the same role that in step 1,
    that means, he selects "Administrators".
  4. User clicks OK in the New User screen
  5. User clicks Save in the Role screen.
  6. System shows a SQL error with a message of duplicated key.

Any workaround?

Thanks,

Answers approved by DevExpress Support

created 7 years ago (modified 7 years ago)

This is a specificity of the XAF UI when a many-to-many association is shown.
One of the ways to resolve this issue is to use a nested Object Space for popup windows shown from the Many to Many collection. To do this, override the GetObjectSpaceToShowDetailViewFrom method in your application's WebApplication descendant. Here is an example of how to change such windows:

C#
public override IObjectSpace GetObjectSpaceToShowDetailViewFrom(Frame sourceFrame, Type objectType, TargetWindow targetWindow) { if(sourceFrame is NestedFrame && sourceFrame.View != null && sourceFrame.View.Id == "PermissionPolicyRole_Users_ListView") { return sourceFrame.View.ObjectSpace.CreateNestedObjectSpace(); } else { return base.GetObjectSpaceToShowDetailViewFrom(sourceFrame, objectType, targetWindow); } }

Note that in this case, you will need to click Save in the parent DetailView to save all changes made in the popup windows.

    Comments (1)
    AG AG
    Alex Gn (DevExpress) 6 years ago

      We fixed this issue and the corresponding changes are included in version 18.2.7. See the Core - Exception is thrown when a link is added to many-to-many collections in different ObjectSpaces ticket for details.

      Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

      Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.