Ticket S18093
Visible to All Users

Can persistent objects be used as a part of a composite key with NestedUnitOfWork or IObjectLayer?

created 17 years ago (modified 6 years ago)

Here is some sample code:

C#
[Persistent("Customers")] public class Customer : XPObject { public Customer(Session session) : base(session) { } [Association, Aggregated] public XPCollection<Order> Orders { get { return GetCollection<Order>("Orders"); } } } public struct OrderKey { [Persistent("OrderID")] public int OrderID; [Persistent("CustomerID"), Association] public Customer Customer; } [Persistent("Orders")] public class Order : XPCustomObject { public Order(Session session) : base(session) { } [Key, Persistent] public OrderKey Key; }

It's not currently supported, but it seems to work in a simple Session. However, it doesn't work in NestedUnitOfWork or when Object Access Layer is used.

Solutions
1. Modify your database schema to avoid composite keys.
OR
2. Remove persistent references and associations in composite keys. Instead, declare scalar properties in your composite key structure and programmatically load associated data in dependent classes (collections or referenced objects by their keys). Download and research the Q472391 example for more information.

Comments (3)

    Is there any workaround?

    Dennis Garavsky (DevExpress) 11 years ago

      @Franco: I am afraid we do not have good solutions for this particular scenario at the moment, and,  to be honest, we will unlikely support this in the future.
      Support for composite keys is provided just for backward compatibility with legacy databases and is not primary for ORM frameworks like XPO.

      I can only suggest you design your database schema so no composite keys are used or, if this is possible, store plain key values using simple type properties in the structure.

      MB MB
      Mevlüt Budak 1 9 years ago

        Is there any update on this Topic?

        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.