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.
Is there any workaround?
@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.
Is there any update on this Topic?