Entity Framework 1to1 relationship via association table not working in EDMX
c#, edmx, entity-framework, entity-framework-6, sql-server
Solution
It is a "bug" with the entire EF design: Entity Framework 4-6.1x Only Honors Multiplicity on Primary Keys.
Thus even though we know (and the RA models) that it is a 1-1 relationship due to a Candidate Key Constraint, EF does not and will not like it. Tough luck.
The "solutions" include:
Changing the model to something EF understands (EF understands Code First, not RA). Granted this may indicate an "issue" with the selected RA model, but such is orthogonal to the question ..
Live with the incorrectly generated multiplicity rules and "use with care"; the dirty work can be wrapped, but has to be added manually outside of the auto-generated model.
.. Hmm, others?
Shameless plug to unresolved questions deal with the same core lack-of feature:
How to get EF6 to honor Unique Constraint (on FK) in Association/Relationship multiplicity?
How to add an EF6 Association to a Candidate Key / Unique Key which is not the Primary Key?
Problem
I have the following tables in SQL Server database Which has a 1-1 association table (FooBar) which has unique indexes on corresponding FooId, BarId, and the primary key is (FooId, BarId). To be clear FooBar does not allow any FooId (due to unique constraint) to be in the table more than once neither can any BarId (due to unique constraint) be in the table more than once. This is what makes it a 1-1 associative table. I want to have this association table instead of 1-1 relationship between Foo and Bar because in my real world scenario, Bar will have other relationships to different unrelated tables and I will want similar association tables (as opposed to adding new FK columns to Bar for each new table) Which I then bring these tables into my EDMX designer. The relationship is brought in as a Many to Many instead of One to One. Which of course isn't what I want. I can manually change the model to a 1-1 relationship. But then I get an error (in the designer). Is this a bug or is it not possible to create a 1-1 association in this manner in EF?