Ticket AS9350
Visible to All Users
Duplicate

XPO should not automatically pre-load an associated collection when I only need to insert a new object into it

created 18 years ago

If I have the following two objects:
public class Product
{
   [Key(true)]
   public Int32 Key;
   public String Name;
   private Category _Category = null;
   [Association("Category-Product")]
   public Category Category
   {
      get { return _Category; }
      set {
         Category oldValue = _Category;
         _Category = value;
         OnChanged("Category", oldValue, _Category);
      }
   }
}
public class Category
{
   [Key(true)]
   public Int32 Key;
   public String Name;
   [Association("Category-Product"), Aggregated]
   public XPCollection<Product> Products
   {
      get { return GetCollection("Products"); }
   }
}
Then if I do this:
Product p = new Product();
p.Name = "test product";
p.Category = Session.DefaultSession.GetObjectByKey<Category>(1);
p.Save();
then what happens is that not only is category #1 loaded, every product in that category is loaded, and Product objects are constructed, potentially drawing in lots of other referenced objects as well. If that category is a popular category with thousands of products, that simple insert+update .Save() call turns into a big Select nightmare.
Is there a way to set up my classes so that unless I have previously loaded the Products collection on that category, it won't be loaded when I do the above code?
See also:
In a 1:N relation between two objects, setting the reference in the N side loads the collection in the 1-side, is this intended, can it be avoided?

Comments (2)
DevExpress Support Team 18 years ago

    Thank you for your suggestion. We have an idea how to implement it. Please note that this feature, once it's implemented, will work with UnitOfWork only. Most likely, a nested UnitOfWork will still require loading of all objects to track changes.

    DevExpress Support Team 13 years ago

      Hello,
      I'd like to inform you that we have implemented this functionality in a different way that does not have limitations mentioned in a previous message. It will be available with version 11.2. See ticket S38059 (Add the capability not to load the XPCollection data while adding or removing objects in a One-To-Many association).
      Thanks,
      Michael.

      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.