LinQ to SharePoint – Managed Metadata & Image Fields

In the same way I noticed that fields of type Managed Metadata are not automatically generated by SPMetal. Once again you have to extend your entities. Consider that I want to add a Managed Metadata Field (named “GeographicLocation”) into the Page content type I will use the following piece of code:

Line 6:

  • Name : the internal name of your column
  • Storage : the field into which you will store the field value
  • FieldType : the interesting part. If we search on MSDN we can find this definition for the FieldType : “The value of this property is always a case-sensitive string representation of the name of a class derived from SPField.” Considering that a managed metadata field is type of TaxonomyField we have to use the “Taxonomy” value. Edit : Actually it seems that you can set “Text” as FieldType.
  • The rest of the code is the default implementation.

Et voilà! You can request your page entities and access to the Taxonomy field.

 

Publishing Image Field

The Image Fields used in publishing sites suffer from the same problem. They are not generated by SPMetal by default. Here is the code snippet to add the PublishingPageImage image to the Page Content Type:

The good thing with the ImageFieldValue is that you can access the HTML render of the image with the ImageFieldValue.ToString method 🙂

Enough for today. Enjoy LinQ 2 SharePoint.