我看过很多帖子讨论如何子类化CSharpEntityTypeGenerator
修改 EF Core 写出的内容。 Visual Studio 不喜欢这样并要求安装Microsoft.EntityFrameworkCore.Design
。我已经安装了v3.1.0-preview1.19506.2。
但是,VS 仍然说找不到该类并安装 NuGet 包。
使这项工作有什么魔力?
我想写一个这样的类#nullable disable
被添加并且GeneratedCode
属性被插入。
public class EntityTypeGenerator : CSharpEntityTypeGenerator
{
public EntityTypeGenerator(ICSharpHelper helper) : base(helper) { }
public override string WriteCode(IEntityType type, string @namespace, bool useDataAnnotations)
{
var code = base.WriteCode(type, @namespace, useDataAnnotations);
var old = "public partial class " + type.Name;
var updated = "[System.CodeDom.Compiler.GeneratedCode]\n" + old;
return code.Replace(old, updated).Replace("namespace", "#nullable disable\n\nnamespace");
}
}
更新项目文件中的引用:
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.0.0">
<PrivateAssets>all</PrivateAssets>
<!-- Remove IncludeAssets to allow compiling against the assembly -->
<!--<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>-->
</PackageReference>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)