Search code examples
codefluent

Purpose of Attributes settings on property


What is the purpose of the Attributes settings on Model property ?

I've read about subproducer and would like to achieve what was described here:http://www.softfluent.com/product/codefluent-entities/knowledge-center/how-to-add-attributes-to-codefluent-generated-properties

Trying to set Attributes on a property would modify XML but wouldn't get picked by BOM producer, is there any reason why ?

In the example below, I expected to have a decoration above my MyProperty property, but it didn't happen.

Thanks for your answer,

<cf:property name="MyProperty" typeName="{0}.Namespace.MyEntity" relationSchema="Schema">
      <cf:attribute name="Newtonsoft.Json.JsonIgnore" context="Property" class="">
        <cf:argument name="arg1" expression="value1" />
      </cf:attribute>
    </cf:property>

Solution

  • Attributes are used by the BOM producer. However you set a context that does not fit your need. In fact the property is a relation property so you have to use context="ToOneRelationKeyProperty, ToOneRelationProperty, ToManyRelationProperty, RelationProperties" (you may keep only one of these values) or the default value.

    <cf:entity name="Customer">
      <cf:property name="Id" key="true" />
      <cf:property name="Orders" typeName="OrderCollection">
        <cf:attribute name="Newtonsoft.Json.JsonIgnore" class="" context="RelationProperties">
          <cf:argument name="arg1" expression="value1" />
        </cf:attribute>
      </cf:property>
    </cf:entity>
    

    The BOM producer generates:

    [Newtonsoft.Json.JsonIgnore(arg1=value1)]
    public Model1.OrderCollection Orders