Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mapping Table to Entity

I already have a project in Entity Framework. The Model1.edmx file has several Entities which come from SQL Server Database. I added a new table in SQL Server Database. And I added a new entity in Model.edmx. And when I try to map this new entity with newly added database, that database does not show up in the table mapping. Help Please.

like image 642
Merin Nakarmi Avatar asked Oct 11 '22 16:10

Merin Nakarmi


2 Answers

Instead of manually adding the entity and trying to map them; why dont you try to to use the update from database option when you right click the edmx file. Select your newly created table and the model should regenerate itself with proper associations and relationships.

like image 110
BentOnCoding Avatar answered Nov 09 '22 07:11

BentOnCoding


It is not a good idea to map entities manually.

To add an entity and map those follow the steps below -

  1. Right click on edmx file and select 'Update model from database'
  2. This will open a window where you can choose and add newly added table.

After doing this, expand your .tt file and ensure that .cs file has been auto generated.

If this is not created, right click on every .tt files and select 'Run custom tool' from the options. This will auto-generate required files.

like image 45
myaseedk Avatar answered Nov 09 '22 07:11

myaseedk