8-Week Microsoft Teams AppDev Accelerator Program
Limited seats available! - Start date: Wednesday, April 16, 2025
Join Today & Save $1,000
articles

Limitations of SPMETAL.EXE for LINQ in SharePoint 2010

SharePoint 2010's LINQ support makes it easier to read/write data to/from lists. SPMETAL.EXE generates entity models for queries but has some limitations.

Limitations of SPMETAL.EXE for LINQ in SharePoint 2010
by Andrew Connell

Last updated July 28, 2010
2 minutes read

Share this

Focus Mode

  • Feedback & questions

The new support for LINQ in SharePoint 2010 makes it much easier to read and write data to/from SharePoint lists. The way it works is that you run a utility SPMETAL.EXE to generate the entity model that is used as the context for the queries. Quite helpful but it only includes the fields (the data types in SharePoint like “single line of text”) that are out-of-the-box in SharePoint Foundation 2010 (SPF2010).

Other fields added by SharePoint Server 2010 (SPS2010), field types added by 3rd parties or custom field types you might create won’t show up in the entity model generated by SPMETAL.EXE. This can be challenging to work with some of the more common field types such as those included by SharePoint Server 2010.

This can be a but frustrating as the LINQ model you generated isn’t a match for your list when you are working with something like the Managed Metadata column. Thankfully there is a very easy way you can extend a SPMETAL.EXE generated entity model.

Consider the following: I’ve created a custom contact list and added a metadata field named Location Tag to it using a Feature receiver the calls the following method:

Taxonomy with LINQ

Taxonomy with LINQ

Next, I generated the entity model by running SPMETAL.EXE against the list. At this point it does not include my custom field Location Tag. Next create a partial class that matches the name of the entity generated by SPMETAL.EXE. In my case this is ContactListWithAutomaticTagsContact and have it inherit from the same type as the entity model does (Contact).

Taxonomy with LINQ

Taxonomy with LINQ

To include the field in the entity the next step is to have the ContactListWithAutomaticTagsContact class implement the ICustomMapping interface. This includes three methods that map the data to the field & vice versa as well as resolve any conflicts:

Taxonomy with LINQ

Taxonomy with LINQ

With this you’ll now have full access to your custom field type, in this case the TaxonomyField, within LINQ queries:

Taxonomy with LINQ

Taxonomy with LINQ

Andrew Connell, Microsoft MVP, Full-Stack Developer & Chief Course Artisan - Voitanos LLC.
author
Andrew Connell

Microsoft MVP, Full-Stack Developer & Chief Course Artisan - Voitanos LLC.

Andrew Connell is a full stack developer who focuses on Microsoft Azure & Microsoft 365. He’s a 20+ year recipient of Microsoft’s MVP award and has helped thousands of developers through the various courses he’s authored & taught. Whether it’s an introduction to the entire ecosystem, or a deep dive into a specific software, his resources, tools, and support help web developers become experts in the Microsoft 365 ecosystem, so they can become irreplaceable in their organization.

Feedback & Questions

newsletter

Join 10,000+ developers for news & insights

No clickbait · 100% free · Unsubscribe anytime.

Subscribe to Andrew's newsletter for insights & stay on top of the latest news in the Microsoft 365 Space!
blurry dot in brand primary color
found this article helpful?

You'll love these!

SharePoint 2010 ECM: Manage Content Lifecycle - WCM, RM & DM

SharePoint 2010 ECM: Manage Content Lifecycle - WCM, RM & DM

May 29, 2010

Read now

Web Content Management in MOSS 2007: Terminology Explained

Web Content Management in MOSS 2007: Terminology Explained

September 7, 2006

Read now

Web Content Management in MOSS 2007: Terminology Explained

Web Content Management in MOSS 2007: Terminology Explained

September 7, 2006

Read now

bi-weekly newsletter

Join 10,000+ Microsoft 365 full-stack web developers for news, insights & resources. 100% free.

Subscribe to Andrew's newsletter for insights & stay on top of the latest news in the Microsoft 365 ecosystem!

No clickbait · 100% free · Unsubscribe anytime.

Subscribe to Andrew's newsletter for insights & stay on top of the latest news in the Microsoft 365 Space!