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?
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 :
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 :
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...
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.
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.
I open the folder where edmx file in, look into all files in it, and find a possible solution.
Edit with Notepad++
then the xml file content will show, or you can directly open the Edmx file by notepad.exeYou'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>
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.
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" />
Restart visual studio, and open the edmx again you'll find DataColumn4
disappear, and I try connect to DB and manipulate Data, works fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With