Entity framework not generating the database classes

entity-framework-6 visual-studio-2019

Question

Using Visual Studio 2019 I recently upgraded all my NuGet packages, so I see that EntityFramework is now showing as 6.2.0. My project is a Web API 2 solution. When I open my database model and right-click to Update Model from Database I can select my new tables but when I save the edmx file it closes immediately. In the past it would run for a bit while it wrote new files.

In the actual .edmx file itself for example I see this entry for my newly added table:

<EntityType Name="Audit_Log">
  <Key>
    <PropertyRef Name="id" />
  </Key>
  <Property Name="id" Type="int" StoreGeneratedPattern="Identity" Nullable="false" />
  <Property Name="Lab_Space_Id" Type="int" Nullable="false" />
  <Property Name="Field" Type="varchar" MaxLength="80" Nullable="false" />
  <Property Name="Old_Value" Type="varchar" MaxLength="1000" />
  <Property Name="New_Value" Type="varchar" MaxLength="1000" />
  <Property Name="Modified" Type="datetime2" Precision="7" Nullable="false" />
  <Property Name="Updater" Type="int" Nullable="false" />
</EntityType>

However, it didn't generate the corresponding class definition for the Audit_Log class. If I completely remove the edmx file and select all my desired tables plus this new one it will generate it correctly.

1
0
5/22/2019 6:42:01 PM

Accepted Answer

This is a workaround for the problem. If you expand the .edmx file in Solution Explorer you'll see two files that end in .tt. Right-click on those and choose to Run Custom Tool and then the classes will be generated. Just doing it on the .edmx file itself didn't work for me.

0
5/22/2019 8:29:16 PM


Related Questions





Related

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