Я видел много постов, рассказывающих о том, как подкласс 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");
}
}