简体   繁体   English

数据库优先实体框架更新 EDMX 但不是 Model.tt

[英]Database First Entity Framework Update EDMX but not Model.tt

I am using entity Database First Entity framework.我正在使用实体数据库第一实体框架。 I have generated my EDMX file in visual studio, as well as the objects (in Model.tt)我已经在 Visual Studio 中生成了我的 EDMX 文件,以及对象(在 Model.tt 中)

I have 1 table (in this example)我有 1 个表(在这个例子中)

Users:
Username varchar
Password varchar
Email varchar

I then added a new column "LastLoggedIn" in my database via SQL manager.然后我通过 SQL 管理器在我的数据库中添加了一个新列“LastLoggedIn”。 So my table now looks like:所以我的表现在看起来像:

Users:
Username varchar
Password varchar
Email varchar
LastLoggedIn DateTime

I then clicked on Model.edmx file and ran the Update Model from Database.然后我单击 Model.edmx 文件并从数据库运行更新模型。 The Table was updated in the EDMX diagram, however the code (in the model.tt - users.cs) file did not update. EDMX 图中的表格已更新,但是代码(在 model.tt - users.cs 中)文件没有更新。

How do I force the objects to update after the EDMX diagram has been updated?更新 EDMX 图后如何强制对象更新?

EF can be a bit of a pain at times, and doesn't like to update. EF 有时会有点痛苦,并且不喜欢更新。 For tables, when this happens, delete the table from the diagram.对于表,发生这种情况时,请从图中删除该表。 Then save it.然后保存。 Then do a right click and choose to Update the edmx.然后右键单击并选择更新 edmx。 This should add the updated table with the new column.这应该添加带有新列的更新表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM