Oct 19, 2009

Early look at LINQ to SharePoint

This post is preliminary and is subject to change, but should give you at least an idea. It refers to build 14.0.4006.1010.

In SharePoint 2007 you have to user CAML to query SharePoint lists. Anybody who have already written CAML queries knows that this can be tedious with complex queries. To make life easier the community had developed various helper tools like the U2U CAML Query Builder, YACAMLQT (Yet Another CAML Query Tool), CAML.NET… Meanwhile .NET 3.5 has been released with a cool new feature called LINQ (Language Integrated Queries). LINQ allows you to query in an object-oriented way, supports compile-time check, gives you intellisense support in Visual Studio and defines a unified, SQL like syntax to query any data source.
var result = from c in Contacts 
where c.FirstName == "Christian"
select c
The abstraction to allow querying any data source has been implemented through an interface called IQueryable(T), but don’t want to go deep in LINQ. Since now Microsoft has been delivered four LINQ providers:
  • LINQ to Object
  • LINQ to XML
  • LINQ to SQL
  • LINQ to Entity
With SharePoint 2010 the fifth LINQ Provider will be available:

LINQ to SharePoint

To don’t overlook the community efforts, there is already a LINQ provider for SharePoint on CodePlex, but since now it is in an alpha stadium.
LINQ to SharePoint works similar to LINQ to SQL or LINQ to Entity. You write business objects (or maybe a DAOs) and decorate them with mapping attributes. When the query will be executed the LINQ statements will be translated to CAML.image
The example class Contact maps to a custom Content Type with the name MyContact and the columns ID and FirstName. Writing this manual is cumbersome, therefore there’s a command line tool called SPMetal, which generates this classes for a whole site. E.g: 
SPMetal /web:http://localhost/anysite /namespace:iLoveSharePoint /code:SPDataContext.cs

Now we want to query our SharePoint list with LINQ. This is done by a class called Microsoft.SharePoint.Linq.DataContext. The DataContext represents a whole web site. SPMetal additionally generates a derived DataContext containing all lists as Properties.

Adding, editing and deleting Items with LINQ to SharePoint

Certainly you can add, edit and delete items with LINQ to SharePoint. To enable change tracking you must (not really all) implement some interfaces in your class:

  • Microsoft.SharePoint.Linq.ITrackEntityState
  • Microsoft.SharePoint.Linq.ITrackOriginalValues
  • System.ComponentModel.INotifyPropertyChanged
  • System.ComponentModel.INotifyPropertyChanging
Don’t panic, SPMetal does the job for you. I recommend to use SPMetal to generate the classes.

Let’s add new contact:

The method SumbitChanges of the DataContext persist all changes (add, edit, delete) to the SharePoint Content DB.

Relations in LINQ to SharePoint 

Another hot topic in SharePoint are relations between lists. In SharePoint 2007 CAML hasn’t any support for joins! This have made it almost impossible to build data centric applications for SharePoint 2007 (among other restrictions). But many, many customer want do that! Now with LINQ to SharePoint comes support for relational queries – Yippee!
Now we extend our sample Content Type with a lookup column to another Content Type called MyCountry and map the relation.


To map a multi Lookup you have to use EntitySet<T> instead of EntityRef<T> and set the MultivalueType property of the Association attribute to Multi. The loading of the relation is deferred. The Country object of the Contact will be loaded from the DB when the property will accessed and not before.
Get all contacts from Germany:

Yet I haven’t verified that this relational query really ends up in a SQL joins If not, this would really be bad. I will verify that as soon as possible…

I think I stop here, because things could change in further builds…


Anonymous said...

One other require stands out as the longines replica See. This may be a jewelry plated, 5 microns chrome steel condition by using a creme tinted synthetic leather bracelet. Any analog indicate regarding bright white switch makes it simple to know the amount of time with regards to crescent silent celestial body together with famous actors over the skin grant it all a truly different appearance. Any gucci replica may be a personally winding utilizing semi-automatic or fully automatic exercise together with water-repellent as many as 50 yards. Whilst a bit of highly-priced, it's together funky together with beautiful all at once. Start on, immerse themselves within the billiards using an louis vuitton replica Semi-automatic or fully automatic FFD0E001B Crescent Silent celestial body Semi-automatic or fully automatic for your wrist and also scalps transform. A good wrist watch shows significantly related to an individual's temperament together with gal favors your girlfriend to generally be dependable and even carry out a good requirement unique i . d. Identifying the have, any breitling replica watches Provider brings about the best together with attractive variations during semi-automatic or fully automatic pieces. may not be mainly beautiful; they're just trendsetters meant for different varieties the fact that get any adolescent iteration.

digital signature said...

Very helpful article ! I was always curious about all these complex algorithms that are being used in these ssl encryptions.

aksawy said...

تنظيف خزانات
شركة تنظيف خزانات بالرياض
تنظيف خزانات بالرياض
تنظيف خزانات
شركة تنظيف خزانات
تنظيف خزانات

Unknown said...

happy hug day 2016
happy hug day 2016 Date SMS Messages Quotes
How Hug Day Is Celebrated
Happy hug day sms

xjd7410@gmail.com said...

20160423 junda
air jordans
cheap oakley sunglasses
kate spade outlet
adidas stan smith
ray ban sunglasses
michael kors outlet
nike air max shoes
cheap omega watches
yeezy boost 350
michael kors outlet online
michael kors outlet online
nike free runs
air jordan uk
michael kors outlet online
pandora charms
ray ban outlet
calvin klein outlet
fitflops sale clearance
toms outlet
nike huarache white
sac longchamp
toms outlet
michael kors outlet clearance
bottega veneta outlet
armani watches
gucci handbags
nike blazer
oakley sunglasses
true religion jeans
cheap jordans
ray bans
bottega veneta handbags
jimmy choo outlet
oakley sunglasses
prada outlet
reebok shoes
true religion
burberry outlet

Justin said...

Utilizing an administration online to discover a car credit for you can be a fantastic approach to look for the most ideal loan cost, since they do all the work for you when you finish the quote. Cash Advance

Justin said...

L'infertilità è fondamentalmente una incapacità biologica di un individuo di concepire o svolgere un ruolo nella concezione. Ci sono diversi costumi sociali che lo rendono straziante per una persona per stare bene con parlare della loro vita sessuale con un medico della fertilità. problemi di erezione 20 anni come curare

Justin said...

On the off chance that you have an auto that has been paid off, an automobile advance might be your best alternative in the event that you don't have excellent credit. For whatever length of time that your auto right now books for over $10,000, utilizing your auto as insurance for the $10,000 credit is extremely conceivable. Payday Loans Carson

Justin said...

Diverse loan specialists have distinctive prerequisites and criteria to be met before getting to be qualified for renegotiating. It is further bolstering your good fortune that you know these necessities before applying with the goal that you don't squander your time applying just to be ineligible at last. Payday Loans Chula-vista

Justin said...

Institutional banks are putting numerous additional stipulations when managing non-proprietor possessed credits since home loan aftermath of 2008. One must hop through obstacles to meet all requirements for a credit. Banks are taking a gander at FICO assessments and obligation to wage proportions. Payday Loans Lemon-Grove

Paulo said...

On the off chance that you are burnt out on paying rent on a manufactured house plot, consider putting resources into your own piece of land with the assistance of a private auto title credit. https://www.usacheckcashingstore.com/san-diego

Robbert said...

Why not arm yourself with the ammo you have to arrive the best arrangement for you. Have the capacity to stroll into the dealership with certainty, realizing that you can beat each trap and obstruction to purchasing that new auto at a cost and on terms ideal to you.https://www.usacheckcashingstore.com/corona

Robbert said...

An auto without support resemble an office without more clean. You abandon it as it is and it gathers all the clean and soil. After some time, you may ponder what's the issue with your office, as everything appears to be so monstrous. At that point you understand the can stinks and later get obstructed. https://www.usacheckcashingstore.com/chula-vista

Robbert said...

Be that as it may, this article ought to have set you up to get readied, in a way. You now realize that purchasing that little blue book is not going to do much to spare you cash on your next utilized auto buy, and you have some bearing on the most proficient method to continue. Definitely, continue! check cashing

Home Improvement NYC said...

Ajrin Construction Inc. is a licensed New York general construction firm working as General Contractors in NYC, truly devoted to our services and remain firm until our Clients’ purposes are served to satisfaction. We feel much concerned of the value of your property, safety and security more than our profit or anything else.
Home Improvement NYC

Garrick Co Ida said...

Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a .Net developer learn from Dot Net Training in Chennai. or learn thru ASP.NET Essential Training Online . Nowadays Dot Net has tons of job opportunities on various vertical industry.
or Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry.

khairy said...

شركة مكافحة حشرات بالدمام

شركة كشف تسربات بالدمام

شركة عزل اسطح بالدمام

شركة تسليك مجاري بالدمام

شركة تنظيف كنب بالدمام

شركة تنظيف مساجد بالدمام

شركة تنظيف سجاد بالدمام

anosh said...

شركة تنظيف خزانات بالباحة
شركة عزل خزانات بالباحة
شركة رش مبيدات بالباحة
شركة مكافحة حشرات بالباحة

anosh said...

شركة تنظيف بيوت بالباحة
شركة تنظيف فلل بالباحة
شركة تنظيف منازل بالباحة
شركة تنظيف شقق بالباحة
شركة تنظيف بالباحة
شركة تنظيف مجالس بالباحة

cara menggugurkan hamil said...

just information we only provide information for those who need it
A. posisi berhubungan agar cepat hamil
B. makanan dan minuman agar cepat hamil
C. panduan agar cepat hamil
D. cara agar cepat hamil
E. cara agar cepat hamil setelah selesai haid
F. cara alami untuk segera mendapat kehamilan

Kale Co Jakim said...

Great Article
IEEE Final Year Projects for CSE
IEEE Project Centers in Chennai

unkown said...

Treasurebox provide you all the items which you will be get online in a single click in Auckland Newzealand. We provide you quality items and all types of outdoor furniture at lowest price.

Pinoy Channel Replay said...

To watch Filipino movies, you can easily log in to Pinoy TV. Pinoy TV is an online Filipino movie streaming website from where you can watch not only comedy but all genre movies of Philippines television industry. You will find not only wow pinoy tambayan but Filipino drama serials, TV shows and morning shows too. As for the Filipino comedy movie list, you should definitely add these two movie names in your list.