Entity-framework – Entity Framework Endpoint Multiplicity

database-designentity-framework

Say I have 3 tables in a Tennis Application (stripped down removing irrelevant info):

Competitions

Id (PK)

Matches

Id (PK)

CompId (FK)

CourtAssignments

CompId (PK),(FK)

CourtNumber (PK)

MatchId (FK), (Unique)

To describe the above:
A match consists of 2 people playing tennis against eachother on a court.
A competition consists of 0 to many matches.

A courtassignment represents a court during a competition (During a single competition, 0 or 1 match may be assigned to a court) Also, a single match can only be played on a single court number, and exists only in a single competition. (so those two fields together form the primary key for the CourtAssignment's table)

Thus the CourtAssignment's MatchId field will ALWAYS be unique or null.

However, when a generate an EF Model from my database. The multiplicity for my CourtAssignment Navigation Property with my Match is *. This should be 0..1.

I am using Visual Studio 2010 beta 2 (with .Net 4 beta 2 and EF 4 beta 2).

I had been using beta 1 and was able to simply change the * to 0..1. However, now having changed to beta 2 since it has a go-live license (porting upgrading my solution worked fine, but re-writing my solution from scratch, I am unable to manuall change * to 0..1 without receiving 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 change the multiplicity to 0..1? I know it is doable since my old solution continues to work that way. I can't seem to make the change in the designer anymore and get completely lost in the edmx file.

Note: I realize changing MatchId to the primary key would generate the correct multiplicity, but I need my primary key to be the composite of [CompId,CourtNumber] as I need to be able to switch which match is on which court on the fly. And obviously it doesn't work changing the primary key.

Thank you to whoever can provide help!

Best Answer

Scott, this isn't the exactl same scenario as you, but it might help:

Unique Keys not recognized by Entity Framework

I think it may be related - perhaps you've got the FK cols exposed in the conceptual model? It seems you can't do a 1 to 0..1 if this is the case.