A while ago I wrote a post about CAML And Linq when working on MOSS, that post was giving an example of what and when to use each one of them ( when you work on MOSS).
Since that post, a newer version of SharePoint came out, the 2010.
Which is definitely worth writing another part ( update ) for that post.
Actually, I should start with the end result, now you can use Linq in all cases and you will get same results ( only in SharePoint 2010 ).
Now, there is the - how come ? Answer : SPMetal.
What SPMetal does ? In a nut shell, creates an entity class that provide another layer in which your Linq code can access directly to the database ( content db ).
Which is in other words, give you the same performance you could only achieve with CAML queries.
So, if you work with SharePoint 2010 you can work with Linq always. You got my approval :)
This blog shares my thoughts and tips with Sharepoint/Moss and SQL Server
Showing posts with label Linq. Show all posts
Showing posts with label Linq. Show all posts
Wednesday, December 1, 2010
Friday, October 9, 2009
How to check if list is a document library ? Let's Linq it !
Sometimes you need to iterate via the Doclibs of a site for a dedicated reason, and there is no need to iterate via the "regular" lists of the site.
Of course it's very easy so you usually just run something like that -
So in order to be more efficient, run only in doclibs, and not on all lists that you have in your website ( including hidden ones ).
How you do that ? very simple.
And to make it even nicer, lets just LINQ it -
Hope it helps.
Of course it's very easy so you usually just run something like that -
SPWeb web = site.Openweb();
SPListCollection listCol = web.lists;
foreach(SPList list in listCol )
{
//Do your thing
}
So in order to be more efficient, run only in doclibs, and not on all lists that you have in your website ( including hidden ones ).
How you do that ? very simple.
SPWeb web = site.Openweb();
SPListCollection listCol = web.lists;
foreach(SPList list in listCol )
{
if(list.BaseType == SPBaseType.DocumentLibrary)
{
//Do your thing
}
}
And to make it even nicer, lets just LINQ it -
var docLibs = from SPList list in web.Lists where (list.BaseType == SPBaseType.DocumentLibrary) select list;
foreach (SPList doclib in docLibs)
{
//do your thing
}
Hope it helps.
Subscribe to:
Posts (Atom)