How do I manually edit table mappings in ADO.NET in Visual Studio 2010?

17,246

Solution 1

It appears the answer is, you can't without going into the XML. You can use the Entity Framework Power Pack to customize the templates for generation, but there's no direct GUI for editing the mappings.

Solution 2

I open the folder where edmx file in, look into all files in it, and find a possible solution.

  1. I advice install the notepad++ first, then right click on the Edmx File in file explorer, and click Edit with Notepad++ then the xml file content will show, or you can directly open the Edmx file by notepad.exe
  2. You'll see something like this on the top part of the file:

    <EntityType Name="DataTableName">
      <Key>
        <PropertyRef Name="id" />
      </Key>
      <Property Name="DataColumn1" Type="bigint" Nullable="false" />
      <Property Name="DataColumn2" Type="datetime" Nullable="false" />
      <Property Name="DataColumn3" Type="nvarchar" MaxLength="255" />
      <Property Name="DataColumn4" Type="nvarchar" MaxLength="255" />
    
    </EntityType>
    
  3. What I want to do is remove DataColumn4, I first open the Edmx File in VS and directly click on the column name in the VS UI and press Delete on the keyboard, and you'll find that in the Mapping Detail Window, the right side of DataColumn4 property will be empty, but in the left side the DataColumn4 still exist.

  4. Then, Open the edmx file using Step 1, remove the property in the Step 2 and save the file.

    Remove--> <Property Name="DataColumn4" Type="nvarchar" MaxLength="255" />

  5. Restart visual studio, and open the edmx again you'll find DataColumn4 disappear, and I try connect to DB and manipulate Data, works fine.

Solution 3

If you have your .edmx file open in Visual Studio, you should be able to simply right-click on a table or a column in the table and choose 'rename'. Once you change the name it will be reflected in the Mapping Details window.

Solution 4

You can edit the names easily... just click on the name (when the item is already selected) in the 'class diagram' or the table representation in the edmx file and type the new name. If the text does not become selected and editable when you click on it, you can press F2, the standard Windows key to raname an object. Note: you cannot edit the name in the mapping window.

After editing the names, you can right click on the entity and select 'Generate Database from Model...' option to update the names in the database.

Also, see this post for more information.

Share:
17,246
Bialecki
Author by

Bialecki

Programmer. Runner. Red Sox fan.

Updated on June 19, 2022

Comments

  • Bialecki
    Bialecki almost 2 years

    I can't seem to find the answer to what I think is an easy question. I have a Entity model I just created and I want to set the name of the table and the columns by hand. I can see the "mapping details," but how do I edit them or add to them?