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

Modelling 1:1 association?

4 Answers 72 Views
Design Time (Visual Designer & Tools)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Kendall Bennett
Top achievements
Rank 2
Kendall Bennett asked on 15 Jul 2011, 03:20 AM
How do I go about modeling a 1:1 association in OpenAccess? In my Entity Framework model, we have some entities that are related to each other in that the primary key is the same for each table (they are basically extensions of the same table). This is modelled as a 1:1 association in the Entity Framework, but when the association was converted over to OpenAccess, it comes over as a 0:Many association so on one end of the association I have a list, rather than a reference.

For instance I might have a Customer entity, and then another CustomerInfo entity that are stored in separate tables because the stuff in CustomerInfo is not used very often (or may not be present for some customers) so it saves space in the database. They both have CustomerID as the primary key, and I need to set this up as 1:1 association? Or a 1:(0 or 1) association in some instances.

When I open the association in the designer, and try to edit it, the type of the association end point is grayed out and I am not able to change it from 0 to many, to 0 to 1 or 1 depending on the entity I am editing. Is there something I have to do differently to model this in the designer? Or do I need to delete the association and re-create it again (does it support 1:1 in that case)?

4 Answers, 1 is accepted

Sort by
0
Kendall Bennett
Top achievements
Rank 2
answered on 15 Jul 2011, 09:04 PM
Reading this post it would appear there is no support for 1:1 associations in OpenAccess:

http://www.telerik.com/community/forums/orm/design-time/dependent-property-and-cascading-delete-in-visual-designer.aspx

So I am thinking perhaps the simplest solution is to create two one-way associations between the Entities, so that the navigation reference properties will be there in both directions, but the navigation set properties would not be there? In code it would look and act like a 1:1 association, but it would really be two 1:Many associations?
0
Zoran
Telerik team
answered on 19 Jul 2011, 05:43 PM
Hello Kendall Bennett,

 I would not recommend you this solution as you might get some inconsistency with your data when fetching the referenced objects. Actually having just one 1:m association is good enough and what you can do to simulate 1:1 is to have a property in a partial class for the class that has the n side of the association. For example you could have something like this:

public Customer Customer
{
get{ return this.Customers.FirstOrDefault(); }
set {this.Customers.Clear();
   this.Customers.Add(value); }
}


All the best,
Zoran
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Kendall Bennett
Top achievements
Rank 2
answered on 19 Jul 2011, 07:56 PM
That is a good suggestion for the case where I need a back reference in code, but it won't work too well when I need a back reference to be used in LINQ queries. For the moment I am just making them one way and getting rid of the collection back reference and I think that will be fine. I usually have little need to go back from the referenced object in the 1:1 association as I can write all my code to just go in one direction.
0
Zoran
Telerik team
answered on 20 Jul 2011, 05:12 PM
Hello Kendall Bennett,

 Actually the restriction to edit the Association ends multiplicity is intentionally forbidden in the Visual Designer, so editing the XML by hand will not serve your needs. At the moment, 1:1 associations can not be modeled as I have described in the other forum thread you have on the same topic. I think we can continue our discussion on the issue there for the future.

All the best,
Zoran
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
Design Time (Visual Designer & Tools)
Asked by
Kendall Bennett
Top achievements
Rank 2
Answers by
Kendall Bennett
Top achievements
Rank 2
Zoran
Telerik team
Share this question
or