Andrew Connell [MVP SharePoint]
1741 Posts |  46 Articles |  5310 Comments
.NET  |  MCMS  |  SharePoint  |  Office System
Andrew Connell's RSS Feed    
AC's Blog Quick Links
SharePoint Quick Links
Article Categories
Archives
May, 2012 (3)
April, 2012 (4)
March, 2012 (4)
February, 2012 (4)
January, 2012 (12)
December, 2011 (6)
November, 2011 (3)
October, 2011 (17)
September, 2011 (8)
August, 2011 (6)
July, 2011 (7)
June, 2011 (13)
May, 2011 (9)
April, 2011 (15)
March, 2011 (1)
February, 2011 (6)
January, 2011 (5)
December, 2010 (11)
November, 2010 (6)
October, 2010 (12)
September, 2010 (5)
August, 2010 (4)
July, 2010 (5)
June, 2010 (6)
May, 2010 (11)
April, 2010 (11)
March, 2010 (9)
February, 2010 (9)
January, 2010 (3)
December, 2009 (10)
November, 2009 (15)
October, 2009 (15)
September, 2009 (7)
August, 2009 (4)
July, 2009 (10)
June, 2009 (8)
May, 2009 (2)
April, 2009 (9)
March, 2009 (6)
February, 2009 (16)
January, 2009 (6)
December, 2008 (12)
November, 2008 (12)
October, 2008 (27)
September, 2008 (13)
August, 2008 (14)
July, 2008 (14)
June, 2008 (12)
May, 2008 (23)
April, 2008 (12)
March, 2008 (15)
February, 2008 (13)
January, 2008 (12)
December, 2007 (10)
November, 2007 (8)
October, 2007 (15)
September, 2007 (20)
August, 2007 (21)
July, 2007 (16)
June, 2007 (8)
May, 2007 (25)
April, 2007 (16)
March, 2007 (18)
February, 2007 (18)
January, 2007 (12)
December, 2006 (16)
November, 2006 (13)
October, 2006 (18)
September, 2006 (22)
August, 2006 (27)
July, 2006 (23)
June, 2006 (23)
May, 2006 (23)
April, 2006 (9)
March, 2006 (17)
February, 2006 (15)
January, 2006 (23)
December, 2005 (31)
November, 2005 (32)
October, 2005 (38)
September, 2005 (53)
August, 2005 (30)
July, 2005 (63)
June, 2005 (30)
May, 2005 (59)
April, 2005 (29)
March, 2005 (74)
February, 2005 (27)
January, 2005 (22)
December, 2004 (32)
November, 2004 (42)
October, 2004 (39)
September, 2004 (20)
August, 2004 (14)
July, 2004 (27)
June, 2004 (40)
May, 2004 (5)
April, 2004 (6)
March, 2004 (16)
February, 2004 (26)
January, 2004 (23)
December, 2003 (7)
November, 2003 (14)
October, 2003 (20)
September, 2003 (4)
Post Categories



Managed Windows Shared Hosting

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:

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).

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:

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

posted on Wednesday, July 28, 2010 7:54 AM

Feedback

# re: Extending LINQ to SharePoint Entity Models for SharePoint Server 2010 or Custom Field Types 7/28/2010 10:01 AM Amit Vasu
Gravatar Awesome!!!.. Great post... Thanks AC..

# re: Extending LINQ to SharePoint Entity Models for SharePoint Server 2010 or Custom Field Types 8/12/2010 4:47 PM Rodolfo
Gravatar Hi andrew

I hope you are well. Could you kindly give me a sample project

Regards

Rodolfo

# re: Extending LINQ to SharePoint Entity Models for SharePoint Server 2010 or Custom Field Types 8/13/2010 11:53 AM AC [MVP SharePoint]
Gravatar @Rodolfo - The post contains enough detail to recreate this on your own.

# re: Extending LINQ to SharePoint Entity Models for SharePoint Server 2010 or Custom Field Types 9/2/2010 1:59 PM Yohan
Gravatar Hi Andrew,

Thanks a lot for the code! Not a lot of references about this on the web...

Have you tried LINQ joins with a custom field type? Seems to be considered an "inneficient query" and it's giving me headaches!

Thanks,
Yohan

# re: Extending LINQ to SharePoint Entity Models for SharePoint Server 2010 or Custom Field Types 10/18/2010 7:08 AM Paul B
Gravatar Pingback: sp2010uk.blogspot.com/.../...blishing-columns.html

# re: Extending LINQ to SharePoint Entity Models for SharePoint Server 2010 or Custom Field Types 11/5/2010 1:46 PM josh meyer
Gravatar Great sample Andrew. Thanks!

# re: Extending LINQ to SharePoint Entity Models for SharePoint Server 2010 or Custom Field Types 10/5/2011 5:34 AM Adil
Gravatar Thanks for this posts,
I'm having problem at the MapFrom function at this line:-
this.BU_SU = item["BU_SU"] as TaxonomyFieldValue;
the error message is Value does not fall within the expected range.
What could be the problem. Appreciate any helps.


# re: Extending LINQ to SharePoint Entity Models for SharePoint Server 2010 or Custom Field Types 11/14/2011 11:39 PM Larkin
Gravatar Would it not be a lot easier to just create a parameters.xml file and manually add the taxonomy column names? Granted, it does generate them as type object, instead of TaxonomyFieldValue or TaxonomyFieldValueCollection, but a simple cast will solve that problem, no?

# re: Extending LINQ to SharePoint Entity Models for SharePoint Server 2010 or Custom Field Types 11/16/2011 3:56 PM AC [MVP SharePoint]
Gravatar @Larkin - A simple cast would do, but then you'd have to communicate that to everyone who may use the column.

# re: Extending LINQ to SharePoint Entity Models for SharePoint Server 2010 or Custom Field Types 4/17/2012 8:26 PM Quinttin
Gravatar Hi andrew

I hope you are well. Could you kindly give me a sample project

faithfully

Quinttin




# re: Extending LINQ to SharePoint Entity Models for SharePoint Server 2010 or Custom Field Types 4/27/2012 12:12 PM Paul Matthews
Gravatar Just got back from ISCLondon, and trying out SPMetal as this seems so cool instead of CAML.
As you have pointed out above, a work around for Managed Metadata Columns, do you also have a work around for BDC columns? Could I use the same principles?

Also can't wait to get hold of the code from ISCLondon.



Post Feedback

Title:
Name:
Email:
(email will not be displayed)
Url:
Comments: 
Please add 5 and 6 and type the answer here:    
All Comments Are Filtered & Moderated
Unfortunately comment spammers are just too effecient and are constantly dirtying up blogs with irrelevant and unwanted comments trying to improve their standing on search engines. All comments on this blog are moderated. I do not censor comments, but I don't approve comments with vulger language or those soliciting products. Most of the time comments are approved within a few hours of being submitted with the only exception when I'm traveling.

Why are you asking for my email address?
The only reason I'm asking for your email address, which isn't required to submit a comment, is to provide a gravatar if you've created an account for yourself and associated your email address with a small image. If you have a gravatar created for the email address you submit, it will appear next to your comment. Otherwise nothing will appear.

What is a gravatar?
A gravatar is a "globally recognized avatar." You can get more information about gravatars, as well as create your own for free, at www.gravatar.com. You can also view my gravatar here.


Copyright © 2003 - 2012 Andrew Connell
Creative Commons License 
This work is licensed under a Creative Commons License

 
SharePoint Training
Looking for SharePoint 2010 training for developers, administrators, power users, information workers, end users & web designers? Look no further! My company, Critical Path Training offers the best SharePoint training around! We offer public & private classes both as in-person instructor-loed hands-on classes and online classes. Check out our schedule and course catalog for all the ways we can get you going on your SharePoint path!