Current filter:
                                You should refresh the page.
                                Support Center
                                0
                                  • 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.

                                0

                                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

                                0

                                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

                                0

                                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

                                0

                                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

                                0

                                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

                                0

                                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?

                                [C#]
                                public class Customer : XPObject { public XPCollection RecentProducts { get { ??? } } }

                                Thanks,
                                Nick

                                0

                                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

                                0

                                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:

                                [C#]
                                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

                                0

                                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

                                0

                                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

                                0

                                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

                                0

                                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

                                If you need additional product information, write to us at info@devexpress.com or call us at +1 (818) 844-3383

                                FOLLOW US

                                DevExpress engineers feature-complete Presentation Controls, IDE Productivity Tools, Business Application Frameworks, and Reporting Systems for Visual Studio, along with high-performance HTML JS Mobile Frameworks for developers targeting iOS, Android and Windows Phone. Whether using WPF, ASP.NET, WinForms, HTML5 or Windows 10, DevExpress tools help you build and deliver your best in the shortest time possible.

                                Copyright © 1998-2017 Developer Express Inc.
                                All trademarks or registered trademarks are property of their respective owners