A while back I created a post about SPMetal.
http://www.spdavid.com/post/2010/02/18/Using-SPMetal-to-gernerate-code-for-a-specific-List.aspx
In this post I will expand a little bit on SPMetal and write about how to use it with Visual Studio 2010 in a way that I have found effective.
Create an empty SharePoint 2010 Solution with VS 2010. (Make sure it is .NET 3.5)
- Create a Folder called SPMetal
- Add 3 files to the folder and the following contents
- GenerateSPMetalCode.bat
"C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN\SPMetal"
/web:http://SPDavid /namespace:SPDavid.SPMetal /code:SPMetal.cs /language:csharp
/parameters:SPMetal.xml
- SPMetal.xml
<?xml version="1.0" encoding="utf-8"?>
<Web AccessModifier="Internal"
xmlns="http://schemas.microsoft.com/SharePoint/2009/spmetal">
<List Name="Documents">
<ContentType Name="Document" Class="Document" >
<Column Name="Title" Member="Title" />
<Column Name="Author" Member="CreatedBy" />
<Column Name="Created" Member="Created" />
</ContentType>
</List>
<List Name="Announcements">
<ContentType Name="Announcement" Class="Announcement">
<Column Name="Body" Member="Body" />
<Column Name="Title" Member="Title" />
<Column Name="Author" Member="CreatedBy" />
<Column Name="Created" Member="Created" />
</ContentType>
</List>
<ExcludeOtherLists></ExcludeOtherLists>
</Web>
- It should now look like the following
- Make sure the lists exist in the site that you specified in the bat file.
- Open the SPMetal directory in Windows Explorer and run the GenerateSPMetalCode.bat file.
- After a successful run open up the SPMetal.cs file and confirm that the code has been generated.
- You can now use the generated code with LINQ.
98f8828a-7737-4f7e-be06-3ff8cb3bb7e7|0|.0