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?
We have closed this ticket because another page addresses its subject:
Add the capability not to load the XPCollection data while adding or removing objects in a One-To-Many association
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.
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.