BCS Shims – .NET assembly as a data source for Business Connectivity Services

One of the most powerful new things about the Business Connectivity Services (BCS) component of SharePoint 2010 is the ability to use a .NET assembly as a data source. This assembly is being termed a BCS shim. The Business Data Catalog was great in pulling data directly from a data source such as SQL Server – but if you wanted to do anything complex such as mashing data sources together the best approach was to go through a web service layer. With the BCS able to use a .NET assembly directly now this web service layer can be removed – although if you want to move in a WCF/Services direction the BCS will happily talk to these end points as well, more information on that in a later blog post.

There are two ways in which you can build your BCS shim – using the tooling that comes with Visual Studio 2010 or BCS Meta Man. With the tooling that comes with Visual Studio you still have to understand quite a lot of the underlying BCS model in terms of methods and TypeDescriptors and you also need to write all of your C# code. BCS Meta Man will do all the grunt work for you so that when you drag and drop a table on the design surface it will generate all the BCS model for you and also all the C# code you require. You can then just press F5 and it will deploy straight to SharePoint for you. BCS Meta Man really does build on top of what Microsoft and the Visual Studio team have done for us.

For now we’ll take a look at the tooling that comes with Visual Studio 2010 from Microsoft…

When you create a new BCS Model in Visual Studio 2010 it generates a HelloWorld type BCS model for you. In a later post we’ll go through step by step how to create a custom BCS shim, but for now let’s just take a look at the environment we have to work in and any interesting points. You’ll see on the design surface of Visual Studio the area where you can create your BCS External Content Types and where Microsoft have nicely generated one for you


If you click on your Entity, take a peek at the BDC Method Details window:


This is where you need to define your input and output parameters, as well as create Filters and MethodInstance attributes. Finally check out the BDC Explorer


This window gives you a great overview of your whole model from the root element, through to your LobSystem, methods and TypeDescriptors. This is where you can create the TypeDescriptors that will describe to the BCS the structure of the data being returned by your C# methods. It may take you a while to build up all the TypeDescriptors, and this is where you’ll need to understand the BCS in a bit of detail, but the good thing is once you have done it for one of your methods, you can Copy and Paste a node of TypeDescriptors from one method to the next – just remember you could be copy and pasting errors! 🙂

So what about the actual files that make up our BCS model and our C# code


The highlighted ones are what we are interested in. BdcModel1.bdcm is our BCS model class. It is a DSL diagram that translates the shapes we drop on our design surface to define our External Content Types to the BCS XML that SharePoint 2010 needs.

Each Entity (or External Content Type) that we define on our DSL will have a respective Service class ie our Entity is called Entity1, so our Service class is called Entity1Service.cs.

In this class you’ll find static methods that will be called by our BCS model when BCS methods are executed. In general you’ll have a separate method for your Finder, SpecificFinder, IdEnumerator etc. If you right click on your BCS entity on the design surface and create a new BCS method you’ll see that within Entity1Service.cs it automatically creates the method stub for you. Now you need to write your C# code for that method, and define in your model using the TypeDescriptors the data being returned.

Generally your BCS EntityService class is going to return collections of objects and Entity1.cs is simply a class that describes our object – just some public properties with getters and setters.

Once you have written all your code, and defined your BCS model you can press F5 and Visual Studio will package everything up for you into a WSP and deploy it to the SharePoint server that you picked when you created your project. If you want to debug at all you can place a breakpoint in your code and it will enter debug mode allowing you to step through your code and iron out any issues. If Visual Studio will not hit your breakpoint you may well have a problem with your BCS Model, or Visual Studio is having issues attaching to the correct SharePoint process.


As we are writing C# code the possibilities of where we can get our data and what we can do with it before it gets to the BCS and SharePoint are endless. This makes the BCS so much more powerful that the Business Data Catalog.

It’s also interesting to note that BDC + BCS, and External Content Type and Entity are still somewhat interchangeable terms within the UI. Things certainly should become more standardized as we move to RTM.

In a post coming shortly we’ll do a complete end to end walk through of how to create a custom BCS entity and the necessary BCS model to present your data to SharePoint.


If you’ve any questions or thoughts on the above text please feel free to leave a comment and get the discussion started.


[The information contained above is correct as of 30th October 2009. As of writing w
e are currently working with beta products and although we will do our best to update this post where necessary please note that by the time you are reading this some things will have changed]