Garth
Garth

Reputation:

Ado.Net Entity Data Model Not Updating Correctly

I've done the following steps: - Open visual studio
- Create new item
- Select "ADO.Net Entity Data Model"
- Point it to an existing database
- Accept all the defaults.
- It then adds a "Model1.edmx" file to my solution and the corresponding "Model1.Designer.cs" file.

However in the output I get the following error:
"ERROR: Unable to generate model because of the following exception: 'Value does not fall within the expected range.'."

I've created a model from this database before so I dont think the error is a result of complex table design (which it's not).

Has anyone else hit this error?

Thanks

Upvotes: 6

Views: 8729

Answers (10)

Yaya
Yaya

Reputation: 620

Reason seems to be simple : lack of Primary Key Column.

Upvotes: 0

Esi
Esi

Reputation: 395

I had same problem, the easy solution is : delete your model from visual studio and and new ado.net model with same name, before that delete all connection string from config file

Upvotes: 0

Clen
Clen

Reputation: 11

I experienced the same issue with a MYSQL database using Ria services.

Solution:
I found the entity model requires a primary key in at least one table when multiple tables are imported.
The primary key for my table was also set to auto increment.

Upvotes: 1

Doctor Jones
Doctor Jones

Reputation: 21664

I've just been investigating a similar issue. It turns out that Entity Framework outputs additional error information in the Messages section of the Error List window in Visual Studio.

As you can see it's much more useful than the generic error that appears in the Output window. This was crucial in helping me to solve my problem.

enter image description here

Upvotes: 0

Parminder
Parminder

Reputation: 3158

You can add one table to the model first and when the edmx file is created, you can update model from the database. It worked for me. I wish it solve ur prblem too.

cheers Parminder

Upvotes: 0

Sergio Vicente
Sergio Vicente

Reputation: 990

When I'm unable to open the 'Design View' while clicking on the model.edmx file I Unload the project in VS2008 and then load it back up again and it seems to fix that problem.

Upvotes: 1

Gokulnath
Gokulnath

Reputation: 1256

Please check whether the primary key has been defined for the table. If you open the entity model in xml editor, you should be able to see commented error message, the comment might help you!

Upvotes: 1

Adam
Adam

Reputation:

I had a similar problem. The reason was pretty simple. I've forgotten to set a primary key in one of my tables. Hope it helps.

Upvotes: 2

Garth
Garth

Reputation:

Ok.
I was able to readd it. Here's what I did.

All the steps above in the bullet points plus:

  • Shut down Visual Studio 2008
  • restart Sql Server 2005
  • Reopen Visual Studio 08.

Still stumped on how to resolve this.

Upvotes: 1

Garth
Garth

Reputation:

Ok....
I think I might have a solution. I've just done the following and it worked.

  • Create a new project
  • Add an Ado data model to it.
  • So the ONLY thing in the project is the model and it does not reference any other projects so it can stand and build on it's own.
  • I got the error I was mentioning above in this project
  • Delete the Model1.edmx file.
  • Remove the project reference to "System.Data.Entity.dll" (this was the key)
  • Delete the connectionStrings out of "App.config"
  • Rebuild the Project
  • Add the "ADO.Net Entity Data Model" back into your project.

It now works.
Un-nerving.
But it works.

Upvotes: 1

Related Questions