In Visual Studio 2010, how can I manually modify table mappings in ADO.NET? entity-framework 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?

5/6/2010 9:23:49 PM

Accepted Answer

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.

5/7/2010 9:18:57 PM

Popular Answer

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">
        <PropertyRef Name="id" />
      <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" />
  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.

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow