Endpoint Multiplicity in Entity Framework

database-design entity-framework

Question

Let's say I have three tables in a tennis application (stripped of unnecessary information):

Competitions

Id (PK)

Matches

Id (PK)

CompId (FK)

CourtAssignments

(PK), CompId (FK)

CourtNumber (PK)

(FK), MatchId (Unique)

To explain the aforementioned Tennis is played between two players in a match on a court. An event consists of one or more matches.

During a competition, a court assignment symbolizes a court. (A court may be given 0 or 1 match during a single tournament.) A single match also exists only in a single tournament and can only be played on a single court number. (Therefore, those two fields combined make up the CourtAssignment table's primary key.)

Thus, the MatchId field of the CourtAssignment will ALWAYS be either unique or empty.

However, I use my database to construct an EF Model. My CourtAssignment Navigation Property's multiplicity with my Match is *. It ought to be 0..1.

I'm using beta 2 of Visual Studio 2010 (with .Net 4 beta 2 and EF 4 beta 2).

I was using beta 1, and I only needed to alter the * to 0..1. Now that I have switched to beta 2 since it has a go-live license (porting and updating my solution went without a hitch, but completely rewriting my solution, I am unable to manually convert * to 0..1 without getting an error:

Error 113: Multiplicity is not valid in Role 'CourtAssignments' in relationship 'CourtAssignments_MatchId_FK_Matches_Id'. Because the Dependent Role properties are not the key properties, the upper bound of the multiplicity of the Dependent Role must be *.

Question

How can I make the multiplicity range from 0..1? I am certain that I can complete it since my previous solution is still effective. I'm absolutely confused in the edmx file and can't manage to make the adjustment in the designer any more.

I'm aware that making MatchId the main key would provide the right multiplicity, but I need my primary key to be a composite of [CompId,CourtNumber] since I need to be able to change which match is playing on which court at any time. Naturally, altering the main key is ineffective.

Thank you to everyone who can assist!

1
3
2/28/2014 9:58:54 PM

Accepted Answer

Scott, while this isn't exactly the same situation as yours, it could be helpful:

Entity Framework does not detect unique keys.

I believe these may be connected; maybe you have the FK cols exposed in the conceptual model. If that's the case, it would seem that you can't perform a 1 to 0..1.

3
5/23/2017 12:13:31 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow