Monday, May 31, 2010

How to use SPMetal in Visual Studio

Scenario:
Sharepoint is relatively big product and lot of small small things can make the developers productive. Here's a small tip to easily generate the entities for LINQ to SharePoint.

Steps:
1. Look for SPMetal locally.
2. Open Visual Studio
3. Go to Tools > External Tools > Add a new tool with below settings

spmetal

Setting:

Title : SPMetal
Command : C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\Bin\SPMetal.exe <-- ( This is default location where SPMetal is installed )
Arguments : /web:http://intranet.contoso.com /namespace:SKN.Samples /code:TeamSiteDataContext.cs

Use Output Window : Checked
Output as Unicode : Unchecked
Initial Directory : $(ProjectDir)
Now just go to Tools > SPMetal , once it runs you will see a new file in the project directory , include it in the project and use it.

Recommended:
SPMetal generates code for all the list / libraries and so its better to start with Blank Site and add required list / libraries to it and then run SPMetal.

Article:
How to: Use SPMetal , SPMetal

0 comments: