Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 703
Bialecki Avatar asked May 06 '10 21:05

Bialecki


People also ask

How to add new table mapping in EF designer?

To add new table mapping, you need to add new entity to .edmx designer by right clicking on .edmx designer and choosing the option to add new entity from the menu as shown below : Let’s say the new table be ‘UserPerformanceRating’ for which I want to create a new Mapping in the existing EF designer :

How to add new table mapping in edmx?

To add new table mapping, you need to add new entity to .edmx designer by right clicking on .edmx designer and choosing the option to add new entity from the menu as shown below :

What are the methods of DataTable in Ado net?

Methods of C# DataTable in ADO.NET: 1 AcceptChanges (): It is used to commit all the changes made to this table. 2 Clear (): It is used to clear the DataTable of all data. 3 Clone (): It is used to clone the structure of the DataTable. 4 Copy (): It is used to copy both the structure and data of the DataTable. More items...

What is a datatablemapping?

A DataTableMapping enables you to use column names in a DataTable that are different from those in the database. The DataAdapter uses the mapping to match the columns when the table is updated.


2 Answers

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.

like image 187
Bialecki Avatar answered Oct 29 '22 02:10

Bialecki


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.

like image 22
yu yang Jian Avatar answered Oct 29 '22 01:10

yu yang Jian