Some questiones and answers about Entity Framework

Source: Internet
Author: User

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 'entityiner iner '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 'entityiner iner '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 wocould only to this if the database is not in production yet!

So in SQL Server Management studio firstCreate 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 isDelete the table. Right Click again and select 'delete'. Confirm the Delete.

Back in Visual Studio doUpdate of the Model.

Go back to SQL Server Management studio andRun the 'create' scriptYou have just created.
The table will be added to your database again.

In Visual Studio you can nowDo an update again, Your table will show up under the 'add' Tab !!!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.