Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

When I create a list in SharePoint and want to run LINQ agaisnt it I use SPMetal to auto generate the mapping.

SPMetal.exe /web:http://mysite /code:C:\MyFile.cs

This does not seem to generate the bindings for extenal lists. How could I generate the bindings?

Would I be better off not using LINQ and using the SharePoint Object Model ( http://www.zimmergren.net/archive/2010/01/19/sp-2010-programmatically-work-with-external-lists-bcs-in-sharepoint-2010.aspx )

share|improve this question

2 Answers 2

up vote 1 down vote accepted

LINQ to SharePoint spmetal.exe does not support external lists http://nileshmandekar.blogspot.com/2011/04/limitations-of-external-list-using-bcs.html

But there is an article how to make it work: http://fabiangwilliams.wordpress.com/2010/01/03/how-to-using-spmetal-utility-in-sharepoint-2010-to-presumably-manipulate-data-on-a-bcs-external-list/

I suggest to use SharePoint Object Model as a more tested & recommended API for working with External Lists

share|improve this answer

If the objective is just to query lists using LINQ and you can directly do that without SPMetal. LINQ can be directly used on SPListItemCollection e.g.

SPlist CustomerList = Web.TryGetList("Customers");  
var FindCustomer = from SPListItem Item in CustomersList.Items
                   where Item["Orders"] as int == 5
                    select Item;

//or select new{Title = Item["Title"]}

This does not have hard coded entities but is more flexible. And as long as your list column names remain same, code can be deployed on any environment without recompiling (even if other lists are changed). Also you can choose to retrieve few chosen field's data instead of retrieving data of all the fields every time.

share|improve this answer
    
Thus you get all items from list (Items property) and do a query in memory (Linq to Objects), in case of many items it will decrease performance. –  Yuri Leontyev Dec 20 '11 at 11:07
    
I glad you posted about the performance. It is not great at all. I have a big BCS list 1,000,000 items so it is not fast. Will try CAML way to see if that improves things. If not I may skip a SharePoint list completley. –  John Dec 20 '11 at 11:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.