One-Many and Many-Many associations require that the object model contains an end point at each end of the association. This is not always convenient and imposes an artifical constraint on the object model.
Could you please add support for one-way associations, such as:
public class Customer: XPObject
{
public XPCollection<Order> Orders {…}
}
public class Order: XPObject
{
// No association back to Customer!
}
This article in the forums is a related discussion:
http://community.devexpress.com/forums/p/70054/239050.aspx#239050
Thanks
Sean
Proposed Solution:
Maybe use a link table to store the one-way associations, as you do for many-many associations.
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.
You indeed can acheive this using a link table, as I mentioned in my request. The table has two fields that holds the ids of the containing and the contained items and is unique across those two fields.
Regards
Sean
Hello Sean,
We have found an intermediate solution to your task. Please explore the attached sample project. It uses a link table to represent a one-to-many association between two objects which aren't linked to each other directly at the database level. Hopefully, it will come in handy. We'll appreciate your feedback on our sample project.
Thanks,
Nick
Hi Nick
I'm not sure that it's for me to suggest implementation specifics as you
guys are the XPO experts. However, as you're asking, I would suggest that
you approach it as I suggested in the original suggestion and use a link
table to store the one-way association. This is the same as the data
structure you use to store a many-many association. The only difference is
that you only select from it from one side.
I hope that makes sense - let me know if it doesn't.
Cheers
Sean
Hello Sean,
There is one more thing we need to clarify. What is your situation, which prevents you from defining the associated member in your persistent class? Said differently, please describe your Use Case.
Thanks,
Nick
Hi Nick
Other than the discussion in the DX forums, I've put some stuff up on my blog here (http://kearon.blogspot.com/2008/11/why-support-one-way-multiple.html).
HTH
Sean
Hello Sean,
Thank you for the explanation. However, your example doesn't provide the implementation of the Customer.RecentProducts property. There is just the "get" keyword. Could you please explain how the Customer.RecentProducts property is implemented?
public class Customer : XPObject { public XPCollection RecentProducts { get { ??? } } }
Thanks,
Nick
Hi Nick
I am actually calling GetCollection<T>(string) in the getter, as you would normally do. However, I am also using C# automatic properties with XPO, but that is incidental. I use code enchancement to do that (with PostSharp - http://www.postsharp.org/). If you are interested, you can read my posts here and here; there are links to downloadable code examples also, as there was with the post about implemting one-way multiple associations.
Cheers
Sean
Hi Sean,
The GetCollection<T> method expects the name of an associated property as a parameter. In your situation, you should explicitly create an XPCollection object:
public class Customer : XPObject { private XPCollection<Product> recentProducts; public XPCollection<Product> RecentProducts { get { if(recentProducts == null) { CriteriaOperator filter = ... // define some filter to select recent products for a given customer recentProducts = new XPCollection<Product>(Session, filter); } return recentProducts; } } }
You can find tons of examples about creating CriteriaOperator filters in the Support Center. Please feel free to ask additional questions.
Thanks,
Nick
Hi Nick
Your solution is indeed workable in the described scenario, but my request for one-way associations has nothing to do with a supporting a specific scenario. It is to reduce the code necessary to support a 0…* association in situations where you do not need or want a reverse link.
I'm also confused as you have previously set the request to be "Accepted - Release TBD", but you have now set it to "Rejected". Couild you please clarify why?
Thanks
Sean
Thanks
Sean
Hi Sean,
We've been discussing your suggestion, trying to figure out the real-world task it solves. If we understand you correctly, you only want to simplify the code by not having to declare one of the required properties in associated classes.
A one-to-many association in XPO is a linkage between two persistent classes. According to XPO's association design, the class on the "many" side must hold a reference to the class that represents the "one" side. This is a mandatory requirement put into the foundation of XPO's one-to-many associations. That is, if you want to establish a one-to-many association via the Association attribute and the GetCollection method, you must declare referencing properties in both classes.
However, nothing can stop you from developing one-way association as shown in my previous message. This approach allows you not to add a backward reference property to the dependent class, when it's not required.
To sum it up, we think that the current design of one-to-many associations in XPO is reliable and transparent. We are not going to change it, unless we have strong arguments for doing so.
Thanks,
Nick
Hi Nick
Thanks for the explanation and the consideration of my request. If always having two-way multi associations is a fundamental principle of XPO class design, then I can see that you are nto going to want to change from that. I would like to update my blog - I presume that you do not mind me quoting your response below? Quoting it in a favourable light, of course!
Thanks again for your time and consideration of the request.
Regards
Sean
Hello Sean,
Yes, please feel free to quote me in your blog. Should you have new technical questions, please don't hesitate to ask - I'll be happy to assist you.
Thanks,
Nick