Freigeben über


SP2010: SPMetal Doesn't work for external lists + Possible workaround

As we know SP 2010 has introduced a way where we will now be able to implement OOPS principles for SharePoint Code. In other words we can now have an easier way to understand and implement object oriented principles in SharePoint. The short answer on how to do this is - LINQ + SPMetal tool.

I recently started usign SPMEtal and was amazed how easily I abstracted the logic and got design time checking of web, list schemas, content types, etc. During my testing of SPMetal and LINQ combination I found one bug (or should I say a lacuna). This doesn't work for External Lists. Possible reasons could be:- Since for normal lists the schemas are implemented as SPFields or in other words you know of the fields before hand. In case of external lists these fields are generated on runtime and hence the gap.

To workaround this problem I created a new list and had my list have look up columns to the External list. there after I ran SP metal and was able to get the columns of the new list and the data. I know a lousy workaround but still worked for my scenario. You can also refer to the blog article for full blown example - https://fabiangwilliams.wordpress.com/2010/01/03/how-to-using-spmetal-utility-in-sharepoint-2010-to-presumably-manipulate-data-on-a-bcs-external-list/