Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework Designer Won't add table

I have a simple table named ZipCodes that contains ZipCode, City and State. I create a new class library project, add an ADO.NET Entity Data Model to the project, Select the ZipCodes table from the database, pick the connection string, check the box next to the ZipCodes table and click "Finish" and it generates the edmx and Designer.cs files... but no ZipCodes. The table definition is not on the designer screen and it is not in the .cs file. How can this be?

like image 929
Bob Jones Avatar asked Nov 15 '11 21:11

Bob Jones


3 Answers

Rightclick on the EDMX file. Select "Open with..."

Select your preferred text editor, preferably one that handles XML well.

Find the XML

<EntityType Name="TableNameYouNeedToRefresh">
...
</EntityType>

And remove it.

Also remove:

<EntitySet Name="TableNameYouNeedToRefresh" EntityType="Self.TableNameYouNeedToRefresh" Schema="SchemaOfTableYouNeedToRefresh" store:Type="Tables" />

Now save and close the file. Open the diagram again in EDMX view on VS. You can now add the table again. This should re-created model as you need it to look.

Provided of course your database table is created correctly.

like image 66
Morten Bork Avatar answered Oct 18 '22 00:10

Morten Bork


Burried in the edmx file is a comment:

Errors Found During Generation: warning 6013: The table/view 'Common.dbo.ZipCodes' does not have a primary key defined and no valid primary key could be inferred. This table/view has been excluded. To use the entity, you will need to review your schema, add the correct keys, and uncomment it.

like image 43
Bob Jones Avatar answered Oct 18 '22 00:10

Bob Jones


I had the same issue. But lack of PK was not the problem ( I was able to add other tables with no PK) The problem was that at least one column shouldn't allow null, and in this case null was allowed everywhere

like image 7
mirosz Avatar answered Oct 18 '22 00:10

mirosz