I'm trying to use the database-first approach with the EF 5.0 and it doesn't create the correct model for me.
Here is my data structure:
Forums
Users
Posts
Relationships
The problem
The main problem is with the one-to-one relationships in the Forums
and the Posts
table. The model doesn't recognize the ParentForumID
and the ReplyTo
as nullables and therefore creates a one-to-many relationship between the tables (Forum-Forum
and Post-Post
).
Also, when trying to manually change to One-To-One relationship, I get this error:
Error 113: Multiplicity is not valid in Role 'Forum1' in relationship 'FK_Forums_Forums'. Because the Dependent Role properties are not the key properties, the upper bound of the multiplicity of the Dependent Role must be *. ...\Models\Entities\Model1.edmx
The model in Visual Studio (before editing)
I tried using the code-first approach but it produced a poor database result, I then realized that I can configure the behaviour of the database creation but I couldn't find a good resource that explains how to configure it correctly.
I'd rather use the database-first approach since it lets me customize my database but it still generates an incorrect model with many errors.
So my question is:
What is the best approach to do so?
Where can I learn the code first, database first thoroughly?
Why does my visual studio produce such a model?
Why when I try to change the model to fit my needs it gives me the error described before?
Where can I learn about the migration tools? The functions that I can use to configure the database creation?