编辑XmlIgnore的实体框架模板文件.tt

时间:2017-05-09 13:47:01

标签: c# entity-framework entity-framework-6 xmlserializer xmlignore

我有Entity Framework 6模板文件。我想在[XmlIgnore]上加public virtual ICollection,因为它无法序列化。

这个模板文件生成设计器类,我不希望编辑设计器类,以便在生成后编辑设计器类来包含[XmlIgonre]。我想编辑模板,因此public virtual ICollection所有行都将具有[XmlIgnore]属性。

1 个答案:

答案 0 :(得分:0)

你必须找到并编辑它(在你的模型tt文件中):

ip

对此:

<#
        foreach (var navigationProperty in navigationProperties)
        {
            if (navigationProperty.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many)
            {
#>
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
<#
            }
#>
    <#=codeStringGenerator.NavigationProperty(navigationProperty)#>
<#
        }
    }
#>