Menu
It would be rather difficult to convert this code to use Linq to Sharepoint. When using Linq to Sharepoint you must at least specify a predefined or custom content type as type parameter.
See the following code snippet: DataContext topLevelSite = new DataContext(“http: //localhost”); SPSite siteCollection = new SPSite( 'EntityList someList = topLevelSite.GetList(siteCollection.RootWeb.Lists0.Title); In this case, Item is the content type. Your method accepts any column name of any given list. Linq to Sharepoint assumes, that you have at least knowledge about the used content types. In your case, I would prefer the CAML query. Is there a special need you have to switch to Linq?
It would be rather difficult to convert this code to use Linq to Sharepoint. When using Linq to Sharepoint you must at least specify a predefined or custom content type as type parameter. See the following code snippet: DataContext topLevelSite = new DataContext(“http: //localhost”); SPSite siteCollection = new SPSite( 'EntityList someList = topLevelSite.GetList(siteCollection.RootWeb.Lists0.Title); In this case, Item is the content type. Your method accepts any column name of any given list.
Apr 30, 2018 - In case if you have more than 5000 items in a list you must apply caml query to get the filtered list items. (Note: you have to ensure that caml.
Linq to Sharepoint assumes, that you have at least knowledge about the used content types. In your case, I would prefer the CAML query. Is there a special need you have to switch to Linq? In your case, I would prefer the CAML query. Is there a special need you have to switch to Linq?
Thanks for your quick help. My knowledge in Sharepoint and LINQ is rather thin. I just happen to join a project which involves a conversion of SP2007 to SP2010. One of my tasks is to try to convert CAML to LINQ if possible. For some parts, I could do it by learning from examples found on the web. But for the code I cited in the initial question, it looks too generic and I don't know how to make the SELECT from the DataContext. As for the question why to switch to LINQ, I don't know why.
But from a novice perspective, I find that LINQ syntax is more natural than CAML. May be you can help me here, for my learning experience, is there any benefit to use LINQ?
The benefit of using Linq to Sharepoint is that you have strongly typed objects. This makes it easier and less error prone to access the properties of a given type, because you can use the point operator.
With CAML you're using a lot of strings (e.g. For field names) which may be easily mistyped. Both 'languages' (Linq and CAML) can be used to access Sharepoint data. It depends greatly on the requirements.
In your example CAML is the better choice, because you don't have information about any type.