我正在尝试定制MVCScaffolding中使用的T4模板。
我想过滤掉带有NotMapped
属性的属性。
我的问题是属性集合似乎是空的。我已经尝试像下面这样打印属性:
List<ModelProperty> properties = GetModelProperties(Model.ViewDataType, true);
foreach (ModelProperty property in properties) {
if (!property.IsPrimaryKey && !property.IsForeignKey) {
#>
<th>
@Html.LabelFor(x => x.First().<#= property.Name #>)
<!--
<#foreach(var attribute in property.Type.CodeType.Attributes)
{#>
Attribute: <#=attribute.GetType().Name#>
<#}#>
-->
</th>
<#
}
}
#>
我找不到任何实际有效的关于这个问题的信息,目前只能通过反复试错来解决。获取属性或让模板忽略未映射的属性的正确方法是什么?