0

I have Entity Framework 6 template file. I would like to include [XmlIgnore] on public virtual ICollection as it can not be serialized.

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. I want to edit template so all lines with public virtual ICollection will have the [XmlIgnore] attribute.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
BSave
  • 11
  • 4
  • Can you post somewhere the tt file you are using? – Akos Nagy May 09 '17 at 14:03
  • @AkosNagy , I can not post entire tt file but here is the code that is used for Xml <#@ include file="EF.Reverse.POCO.ttinclude" #> <#@ import namespace="System.Xml.Schema" #> <# } #> – BSave May 09 '17 at 14:20
  • The tt file has to be modified at a number of places, but I can only tell where if I see the template. – Akos Nagy May 10 '17 at 11:01

1 Answers1

2

you must be find and edit this (in your model tt file) :

<#
        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)#>
<#
        }
    }
#>
Masoud Sadeghi
  • 357
  • 3
  • 15