This is a migrated thread and some comments may be shown as answers.

Adding records using join tables

3 Answers 100 Views
Data Access Free Edition
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Erik
Top achievements
Rank 1
Erik asked on 04 Apr 2012, 08:58 AM
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

3 Answers, 1 is accepted

Sort by
0
Damyan Bogoev
Telerik team
answered on 04 Apr 2012, 03:21 PM

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. 
0
Erik
Top achievements
Rank 1
answered on 05 Apr 2012, 08:36 AM
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
0
Damyan Bogoev
Telerik team
answered on 05 Apr 2012, 08:48 AM

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. 
Tags
Data Access Free Edition
Asked by
Erik
Top achievements
Rank 1
Answers by
Damyan Bogoev
Telerik team
Erik
Top achievements
Rank 1
Share this question
or