Adding records using join tables

4 posts, 0 answers
  1. Erik
    Erik avatar
    3 posts
    Member since:
    Nov 2011

    Posted 04 Apr 2012 Link to this post

    Hi all,

    I'm noticing strange behavior in the working of join tables in OpenAccess.
    Somehow adding records only seems to work in a one-way direction.

    For example this works:
    if (!product.ProductCategories.Contains(productCategory))
    {
        productCategory.Products.Add(product);
        ProductCategoryManager.Save(productCategory, context);
    }

    But this doesn't work:
    if (!product.ProductCategories.Contains(productCategory))
    {
        product.ProductCategories.Add(productCategory);
        ProductManager.Save(product, context);
    }

    The ProductMagager.Save and ProductCategoryManager.Save simply execute a context.add and context.SaveChanges.
    When using the first code block, the records is saved in the join table. But when using the second block, no exception is thrown but no records are created either.

    Any suggestions?

    Regards, 

    Erik van Rijn
  2. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 04 Apr 2012 Link to this post

    Hello Erik,

    It seems that the association between the Product and the ProductCategory classes is not marked as managed. In order to achieve that please do the following steps:

    1. Select the association from the visual designer;
    2. Press F4 to open the Properties Grid window;
    3. Expand the Target Property tree node and set the Is Managed to True;
    4. Expand the Source Property tree node and set the Is Managed to True;
    5. Save the diagram and rebuild the solution;

    Hope that helps.

    All the best,
    Damyan Bogoev
    the Telerik team
    Want to use Telerik OpenAccess with SQL Azure? Download the trial version today. 
  3. DevCraft banner
  4. Erik
    Erik avatar
    3 posts
    Member since:
    Nov 2011

    Posted 05 Apr 2012 Link to this post

    Hello Damyan,

    Thanks for the update. This seems to do the trick.
    But this leads to a few more questions;

    Why is this set to false by default?
    And what impact does enabling it have on our applications?

    Regards,
    Erik
  5. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 05 Apr 2012 Link to this post

    Hi Erik,

    By default, the IsManaged property is set to False for all your associations for performance reasons. Setting IsManaged to True could lead to decreased performance when working with large databases, containing hundreds of thousands of objects participating in such relationships. That's why the default value for IsManaged is False.

    You could find this help article helpful, it shows how the managed collections are handled in OpenAccess ORM.

    Hope that helps.

    Greetings,
    Damyan Bogoev
    the Telerik team
    Want to use Telerik OpenAccess with SQL Azure? Download the trial version today. 
Back to Top