Sunday, 15 May 2011

SPLINQ - Parameter.xml to show hidden fields

Problem:  I can never remember the syntax for the parameters files and need to lookup how to include hidden SP 2010 fields in the LINQ to SharePoint Proxy.

Initial Hypothesis:  Use a Parameters.xml file to get SPMetal to generate the proxy with hidden fields.  You can use the IncludeHiddenColumns element within the ContentType element to include all hidden fields or as I have done in the resolution example, specify the fields to include using the element Column.

1.> Create a parameters.xml (name it for you specific project) and add it to the 14\bin directory.
2.> Use the dos cmd prompt to generate the LINQ to SharePoint Proxy.
3.> Add the generate LINQ to SharePoint proxy code to your Visual Studio project. 
4.> Add the query to show 1 of the hidden fields that is now part of your proxy.
The code above uses the default Microsoft.SharePoint.Linq.DataContext class to retrieve the data, it is easier to use your own DataContext class created when you build your LINQ to SharePoint proxy code.  Code below shows how to use the proxy generate data context.

More Info: You can use the same technique for custom site columns however, you will need to manually edit the proxy to perform the appropriate casting.  I would still use the iCustomMapping interface for custom site columns.

Wes Hacket gave me this tip - Using CKSDev you can create a new SPI template that generate the proxy.  With the proxy comes a parameter file, a custom code file and you can regenerate the proxy by right clicking on the proxy and running the SharEPoint Generator tool.  Screent shot to come!

SPMetal Code Generation Rules - 


Post a Comment