How To: Using SPMetal Utility in SharePoint 2010 to “presumably” manipulate data on a BCS External List 5


Synopsis

So this blog started out with me trying to prove that can use LINQ to SharePoint via the SPMetal Utility in SharePoint 2010 to gain access to Business Connectivity Services (BCS) External Content Types // External Lists. In plain English, I wanted to use LINQ to SharePoint in as little code as possible and without using the BCS Template to do CRUD actions to External Lists created in SharePoint. I found out out that I was unable to using SharePoint 2010 BETA and Visual Studio 2010 Beta 2… basically SPMetal did not create the necessary Entity Classes for External Lists in the resultant C# file.

Therefore, I will turn this blog into a How-To for using the SPMetal Utility and point you to Serge Luca Blog for some great Web Cast on just how to use LINQ to SharePoint to access Lists in SharePoint 2010!

So the first thing you can do is bone up on SPMetal. You can read up on it at http://msdn.microsoft.com/en-us/library/ee538255(office.14).aspx or BING “SPMetal SharePoint”

clip_image001

Next I picked a SharePoint 2010 Site that had few clutter and still had List Created OOB that I could play with.

clip_image002

I settled on my “Charlie” Site

clip_image003

Next, I added an External Content Type to create an External List called “A Few People I Know” which resulted in the two screen shots below…

clip_image004

clip_image005

Then just to make sure I do my due diligence, I created two Custom Lists

  • One List that will do lookups to my external List but remains a custom list
  • One List that will just be a custom list with regular columns

clip_image006

So in my list called “Regular People I know List” I am doing lookups to my External Lists Data…

clip_image007

My Resulting List looks like below…

clip_image009

Then I created my RegularPeopleNOLookup List which is just a vanilla list with stuff in it.

clip_image010

Now Time for the FUN! Stuff, we get to crack open Visual Studio 2010 Beta 2 and Code Away!

Steps I took that led be to below..

  • Created a Console Application
  • Set the Build Type Platform to “Any CPU” since i am on a x64 bit system
  • Add References to
    • Microsoft.SharePoint
    • Microsoft.SharePoint.Linq

clip_image011

Next I will use SPMetal to create located in the “BIN” folder under the “14-Hive”, is that what we are calling it… I cant remember, but I know we were given the nomenclature in Vegas! :-)

clip_image012

The syntax for the utility against my Charlie Site is below..

clip_image013

At this time now as you can see in my working folder, I have a file created called “CharlieSiteLists.cs” which is where the Entity Classes are located for the Lists in the “Charlie” site… My HOPE is/was that I will get my External List showing up too.. bummer it didn’t…

Below you have the “CharlieSiteListDataContext” which is basically your wrapper to the Content Database through LINQ

clip_image014

clip_image015

 

clip_image016

Below you can see the Entity Classes representative of the SharePoint List in the “Charlie” Site.

clip_image017

 

clip_image018

What helps us out here is that the Entity List Class implements IQueryable and IEnumerable which will help us out in our LINQ operations.

image

So here is where I will bail out…since I wasn’t able to get to my SharePoint –> Business Connectivity Services –> External Content Type –> External List that I created in my Lab. So Just to show you how it LINQ to SharePoint works see below how I add a data element to my List… MUCH better examples and walkthru are available on Serge Luca’s Blog.

clip_image019

clip_image020

Have Fun with That! Hopefully the story changes with External List when RTM comes out… that’d be really cool.


Leave a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

5 thoughts on “How To: Using SPMetal Utility in SharePoint 2010 to “presumably” manipulate data on a BCS External List

  • Richard Reukema

    I was hoping that external lists would be accessible as well. Did you hear or find out anything more in regard to this functionality? Being new to SharePoint, I figured that once the external content type was created, it would be listed along all the other content types – like an ODBC abtracts away the actual persistance engine (SQL, Excel, etc.).

    Where in SharePoint do they list “external content types” other than “Manage Service Applications”.

    If you could point me to any documentation, it would be greatly appreciated.

    regards,
    richard

    • fabiangwilliams

      I pinged Serge Luca on that but he said there was no capability to do that in the current builds.. not sure if RTM will give us that option, but i will take this opportunity to go bug Serge agian…

  • Richard Reukema

    What would be interesting is just how and why the external types are treated separately from the current content types. This just might be my level of knowledge, but I don’t see why they would be treated differently when we put in all the entity model information to layover the class doing the actual work. Like I said, I would have thought this would abstracted where the content type was getting it’s data, and what operations were defined. In my line of thinking, there should be no difference.