Visual Studio 17.6.1 更新:EF6 不再生成类。

huangapple go评论53阅读模式
英文:

Visual Studio 17.6.1 Update: EF6 no longer generating classes

问题

Visual Studio 更新,Entity Framework 6,Windows 10。

我将 Visual Studio 更新到版本 17.6.1 后,当我重新创建我的 EF 模型(数据库优先)时,没有生成任何类。

在更新之前,这个操作正常工作。

我尝试重新安装 VS 和 EF,但没有生成任何类。

非常感谢任何帮助。

英文:

Visual Studio Update, Entity Framework 6, Windows 10.

I updated Visual Studio to Version 17.6.1 and when I recreate my EF model (DB First) none of the classes are generated.

This worked fine right before the update.

I tried reinstalling VS as well as EF, but none of the classes are generated.

Any help much appreciated.

答案1

得分: 1

  • 我遇到了相同的问题。
  • 我在<b>EF6.Utility.CS.tt.include</b>文件中进行了一次修改。
  • 在编辑之前,请复制此文件,以防您想要还原。
  • 它的位置在这里:"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes"文件夹中。
  • 在第1920行更改前的代码:
private DynamicTextTransformation(object instance)
{
    _instance = instance;
    Type type = _instance.GetType();
    _write = type.GetMethod("Write", new Type[] { typeof(string) });
    _writeLine = type.GetMethod("WriteLine", new Type[] { typeof(string) });
    _generationEnvironment = type.GetProperty("GenerationEnvironment", BindingFlags.Instance | BindingFlags.NonPublic);
    _host = type.GetProperty("Host");
    _errors = type.GetProperty("Errors");
}
  • 在第1920行更改后的代码:
_generationEnvironment = type.GetProperty("GenerationEnvironment", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
  • 所以只需添加"| BindingFlags.Public"。
英文:
  • I had the same issue.
  • I made a single change in the <b>EF6.Utility.CS.tt.include</b> file.
  • Make a copy of this file before editing it, just in case you want to revert.
  • Its location is here: "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes" folder.
  • Code before line 1920 change:
    private DynamicTextTransformation(object instance)
    {
        _instance = instance;
        Type type = _instance.GetType();
        _write = type.GetMethod(&quot;Write&quot;, new Type[] { typeof(string) });
        _writeLine = type.GetMethod(&quot;WriteLine&quot;, new Type[] { typeof(string) });
        _generationEnvironment = type.GetProperty(&quot;GenerationEnvironment&quot;, BindingFlags.Instance | BindingFlags.NonPublic);
        _host = type.GetProperty(&quot;Host&quot;);
        _errors = type.GetProperty(&quot;Errors&quot;);
    }
  • Code after line 1920 change:
    _generationEnvironment = type.GetProperty(&quot;GenerationEnvironment&quot;, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
  • So only add " | BindingFlags.Public"

huangapple
  • 本文由 发表于 2023年5月25日 20:26:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76332260.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定