现在的位置: 首页 > 综合 > 正文

Some Questiones And Answers About Entity Framework

2012年02月10日 ⁄ 综合 ⁄ 共 1616字 ⁄ 字号 评论关闭

1.Why cannot drag tables from Server Explorer to .edmx designer pane?

Use 'Update Model from database...'option.

2.Why tables doesn't show when re-adding them to entity-model (edmx)?

 

  1. Close your model in Visual Studio.
  2. Open your .edmx file in a text editor.
  3. Search and delete the xml entity elements (see notes below).
  4. Open your model in Visual Studio.
  5. Click Update Model from Database.

To delete all references to a table in your Model:

  • In the 'EntityContainer' element, delete all 'EntitySet' child elements that have the 'Name' attribute set to the value [TableNameToReAdd].
  • In the 'EntityContainer' element, delete all 'AssociationSet' child elements where an 'End' element exists that have their 'EntitySet' attribute set to the value [TableNameToReAdd].
  • In the 'EntityContainer' element, delete all 'EntityType' child elements where that have the 'Name' attribute set to the value [TableNameToReAdd].
  • In the 'EntityContainer' element, delete all 'Association' child elements where an 'End' element exists that have their 'Role' attribute set to the value [TableNameToReAdd].

You want to re-add an entity after it is deleted in the model.
Besides editing the edmx file there's another way to do this.
You will have to temporary delete the table from the database.

note: I would only to this if the database is not in production yet!

So in SQL Server Management Studio first create a script:
right click on the table(s) that correspond with the missing entity in your model. Select 'Script Table as', 'CREATE To', 'New Query Editor Window'.

The Second step is to delete the table. Right click again and select 'Delete'. Confirm the delete.

Back in Visual Studio do an update of the model.

Go back to SQL Server Management Studio and run the 'create' script you have just created.
The table will be added to your database again.

In Visual Studio you can now do an update again, your table will show up under the 'add ' tab!!!

抱歉!评论已关闭.