Using a custom field type in a BCS model

The BCS Team (Business Connectivity Services) wrote an blog post about using complex formatting and custom field types within your BCS model. Obviously this post was the source for the SDK article.

The example shows that you can use a custom field type to render data from external data sources this way:

<TypeDescriptor TypeName="Customer.Address" Name="CustomerAddress" DefaultDisplayName="Customer Address"> 
   <Properties> 
       <Property Name="SPCustomFieldType" Type="Customer.Address">Customer Address</Property> 
   </Properties> 
</TypeDescriptor> 

Well, to help you map this example to your data, I’ll write some more about the SPCustomFieldType property of the BCS model.

This is how a method would look like, if you want to map a column to a custom field type:

<Method Name="ReadItem">
  <Parameters>
    <Parameter Name="address" Direction="Return">
      <TypeDescriptor Name="Address" TypeName="RH.SharePoint.BCS.Address, BCSModel">
        <TypeDescriptors>
          <TypeDescriptor Name="Id" IdentifierName="Id" TypeName="System.Int32" />
          <TypeDescriptor Name="Street" TypeName="System.String" />
          <TypeDescriptor Name="Number" TypeName="System.String" />
          <TypeDescriptor Name="PostalCode" TypeName="System.String" />
          <TypeDescriptor Name="City" TypeName="System.String" />
          <TypeDescriptor Name="GeoCoordinates" TypeName="System.String">
            <Properties>
              <Property Name="SPCustomFieldType" Type="System.String">GeoCoordinates</Property>
            </Properties>
          </TypeDescriptor>
        </TypeDescriptors>
      </TypeDescriptor>
    </Parameter>
    <Parameter Name="id" Direction="In">
      <TypeDescriptor Name="Id" TypeName="System.Int32" IdentifierEntityName="Address" IdentifierEntityNamespace="RH.SharePoint.BCS.Model" IdentifierName="Id" />
    </Parameter>
  </Parameters>
  <MethodInstances>
    <MethodInstance Name="ReadItem" Type="SpecificFinder" ReturnParameterName="address" ReturnTypeDescriptorPath="Address" />
  </MethodInstances>
</Method>

“GeoCoordinates” is the name of my custom field type, specified by GeoCoordinates.

The data source for this BCS model is a LINQ to SQL class, where I’ve implemented a property to concatenate the latitude and longitude which are stored in the backend system.

public string GeoCoordinates
{
  get
  {
    if (Latitude == null || Longitude == null) return null;
    return string.Format("{0};{1}", Latitude, Longitude);
  }
}