8

Edit: the issue is solved in the newer versions of EF. At least that's what I assume since I recently created a new project and followed the same steps and everything went fine! Thanks for your comments and helps. I leave the original question, untouched, below.

I'm using the Entity Framework for the first time. I have a strange problem: I have this small database on SQL Server. Here is the diagram from the management studio:

enter image description here

As you can see, the foreign keys are all defined. To generate the edmx model, I selected "New Item -> ADO.NET Entity Data Model -> Generate from database". This is what I get:

enter image description here

All associations but two are missing! This is odd since the good old L2S could recognize them with no problem:

enter image description here

Can anybody help me fix it?

AlefSin
  • 1,086
  • 9
  • 20
  • With all the time and effort you are going to spend fighting with this tool and trying to figure it out, you could have written your own stored procedures and ADO.Net code and optimized your database performance. If it's this hard for such a simple database, imagine what it will be like in a more complex scenario. – DOK Nov 11 '11 at 15:36
  • Well, I have never used the Entities Framework before so I thought I'm just missing something. Are you telling me that it is really that bad even for simplest things like this? – AlefSin Nov 11 '11 at 15:48
  • I think it's good to experiment with new technology. But I am reminded of this recent tweet by Jeff Atwood: [we have a rule at #stackexchange, everyone who says the words "Entity Framework" has to put $1 in the swear jar.](https://twitter.com/#!/codinghorror/status/109141901483053056) which has been retweeted 100 times so far. – DOK Nov 11 '11 at 16:58
  • Try to delete the all entities & recreate them because when you rectify the relations, or rename columns it doesn't update "i don't know why", but it always happens to me – S3ddi9 Aug 06 '12 at 04:45
  • verify also that you are connected to the right database not to an old one – S3ddi9 Aug 06 '12 at 04:46

3 Answers3

5

The answer to our problem in this case is that we had Unique Non-Clustered Index on some of the primary keys - this caused a problem for the EF model (but not in Linq2SQL). Changing the indexes on these keys to Unique Clustered Index fixed the problem!

Stian
  • 1,261
  • 2
  • 19
  • 38
  • Thanks for your answer. I appreciate that. I asked this question almost a year ago. Between now and then somehow I managed to solve the problem. EF is also updated. Thus at this stage I cannot verify if what you suggested works or not. I added an edit to the top of the question so that others would not waste their time adding new answers. – AlefSin Aug 08 '12 at 08:37
  • We have unique non-clustered indexes and they are mapped right way on EF 4.2 and later – vittore Aug 08 '12 at 23:31
  • As someone wrote in another answer I found to this: "A unique index allows for 1 NULL value, a primary key doesn't allow NULLS. How will you match the NULL when nothing is equal to NULL not even another NULL" – Stian Aug 09 '12 at 06:09
4

Are you checking the option of "Include foreign key columns in the model"?

EF Entity Data Model Wizard Screenshot
(source: msdn.com)

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
amit_g
  • 30,880
  • 8
  • 61
  • 118
1

Check if you have on your properties (on your visual studio project ) selected .Net framework 4 to Target Framework .

Blocked
  • 340
  • 2
  • 5
  • 20