[英]EF6 Code First From Database. Edit template at propertyConfiguration
我已经为暴露代码模板的Entity Framework 6.x项目安装了nuget包。 我正在编辑EntityType.cs.t4。 我已经确定了要更改的代码。
我想将[Required](如下)更改为[Required(AllowEmptyStrings = true)]
[Required]
[StringLength(100)]
public string Address1 { get; set; }
在模板中,此代码似乎可以控制var propertyConfigurations = edm.GetConfigurations(property,Model).OfType();
foreach (var propertyConfiguration in propertyConfigurations)
{
#>
<#= code.Attribute(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();
#>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.