SPMETAL.EXE is command line tool which is used for to generate SharePoint Objects as Entity classes. after that you can use LINQ to SharePoint to Query Add, Delete and Update the SharePoint objects. You can find this tool in 14 hive directory where SharePoint installed %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\\BIN .
For SPMETAL.EXE Defaults code generation rules please refer the following URL http://msdn.microsoft.com/en-us/library/ee537010%28office.14%29.aspx. In this blog we are going to override the default code generation with XML parameters file option.
SPMETAL Command line option Syntax :
SPMETAL.exe … /parameters:XMLParametersFileName.xml
SPMETAL Identifies the path and name of an XML file that contains overrides of SPMetal default settings. mostly we will not reuse exactly the same parameters XML file for different Web sites, so name the file the same as the Web site . This gives us easy to identify the file with site name and make changes.
XML Parameters File Schema
The Top level element is <Web>. Web element has two attributes 1 ) Class 2) Access Modifier. both attributes are optional. You can set class attribute if you do not want SPMetal default name given to DataContext derived class. the same way you can set Class modifier as either internal (in C#) or Friend (in VB.NET ) but the default generated class access modifier is public.
<List> you add this element child to the <Web> element if you want to change SPMETAL generates a property to a list.
please refer the following link for more details http://msdn.microsoft.com/en-us/library/ee535056%28office.14%29.aspx
Sample SPMETAL Parameters XML File
The above picture shows All the Lists in my site. Now i am going to generate the entity class for only Sreenicontacts List by passing XML Parameter file so that i can override default behavior of the SPMETAL.
SPMETAL /web:http://localhost:44119 /code:SreeniLinqSPByParamCtx.cs /parameters:myparam.xml
Here is the class diagram of the Entity which is generated my SPMETAL and passing the above XML Parameters File.
Using XML parameters File options we can override the Default code generation of SPMETAL.EXE.