EF6代码优先从数据库.在propertyConfiguration中编辑模板

本文关键字:propertyConfiguration 编辑 数据库 代码 EF6 | 更新日期: 2023-09-27 18:11:21

我已经为我的实体框架6安装了nuget包。x项目公开代码模板。我正在编辑EntityType.cs.t4。我已经确定了我想更改的代码。

我想把[Required](下面)改为[Required(AllowEmptyStrings=true)]

    [Required]
    [StringLength(100)]
    public string Address1 { get; set; }

在模板中,这段代码似乎控制了这一点var propertyConfigurations = edm。GetConfigurations(财产、模型).OfType ();

    foreach (var propertyConfiguration in propertyConfigurations)
    {
#>
    <#= code.Attribute(propertyConfiguration) #>
<#
    }

我如何进行更改?

EF6代码优先从数据库.在propertyConfiguration中编辑模板

我是这样得到它的。希望这对其他人有所帮助:

    var propertyConfigurations = edm.GetConfigurations(property, Model).OfType<IAttributeConfiguration>();
    foreach (var propertyConfiguration in propertyConfigurations)
    {
        if (code.Attribute(propertyConfiguration) == "[Required]")
        {
#>
    <#= "[Required(AllowEmptyStrings=true)]" #>
<#
        }
        else
        {
#>
    <#= code.Attribute(propertyConfiguration) #>
<#
        }
    }
#>
下面是我调试的步骤:A)复制下列代码行B)保存模板C)删除或注释掉app.config连接字符串(以便创建新的连接字符串)d)删除现有的EntModel.cs文件e)右键单击项目,选择添加新模型(数据->实体框架->数据库中的代码优先)。d)应用程序会提示你打开一个新版本的vs 2015调试器,然后你可以调试。

这一行位于最顶端

<#@ template visibility="internal" linePragmas="false" #>

要复制的代码行1)用这行

代替上面的行
<#@ template language="C#" debug="true" hostspecific="true"#>

2)粘贴到你想要打断的地方

<#  
System.Diagnostics.Debugger.Launch();  
System.Diagnostics.Debugger.Break(); 
#>
相关文章:
  • 没有找到相关文章