[英]Edit Entity Framework template file .tt for XmlIgnore
I have Entity Framework 6 template file. 我有Entity Framework 6模板文件。 I would like to include [XmlIgnore]
on public virtual ICollection
as it can not be serialized. 我想在public virtual ICollection
上包含[XmlIgnore]
,因为它无法序列化。
This template file generates designer class and I do not want to edit designer class to include [XmlIgonre]
by editing designer class once it's generated. 此模板文件会生成设计器类,并且我不想通过在生成设计器类后对其进行编辑来将其包含在[XmlIgonre]
。 I want to edit template so all lines with public virtual ICollection
will have the [XmlIgnore]
attribute. 我想编辑模板,以便所有带有public virtual ICollection
行都具有[XmlIgnore]
属性。
you must be find and edit this (in your model tt file) : 您必须找到并编辑此文件(在模型tt文件中):
<#
foreach (var navigationProperty in navigationProperties)
{
if (navigationProperty.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many)
{
#>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
<#
}
#>
<#=codeStringGenerator.NavigationProperty(navigationProperty)#>
<#
}
}
#>
To this : 对此:
<#
foreach (var navigationProperty in navigationProperties)
{
if (navigationProperty.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many)
{
#>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
[System.Xml.Serialization.XmlIgnore]
<#
}
#>
<#=codeStringGenerator.NavigationProperty(navigationProperty)#>
<#
}
}
#>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.