IT tutorials
 
Technology
 

LINQ to SharePoint and SPMetal : Demonstration Scenario (part 7) - Creating Entities Using SPMetal - Controlling Entity Creation Using a Parameters File

11/24/2013 6:17:51 PM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
3.3 Controlling Entity Creation Using a Parameters File

To save any confusion, it would be nice to rename a few of the entities, particularly the derived entities containing the additional columns. While it’s perfectly possible to do this manually in code, the next time SPMetal is used to regenerate the entities, all changes will be lost and any code that refers to the old entity names will fail to compile. Instead, SPMetal allows for the use of a parameters file.

In Visual Studio, add a new XML file named SPMetalParameters.xml. Insert the following XML into the file:

<?xml version="1.0" encoding="utf-8" ?>
<Web AccessModifier="Internal"
xmlns="http://schemas.microsoft.com/SharePoint/2009/spmetal">
<List Name="Asset Notes" Type="AssetNote">
<ContentType Name="Asset Note" Class="AssetNote" />
</List>
<List Name="On-Hire Assets" Type="OnHireAsset">
<ContentType Name="On-Hire Asset" Class="OnHireAsset" />
</List>
<ContentType Name="Asset Note" Class="BaseAssetNote"/>
<ContentType Name="On-Hire Asset" Class="BaseOnHireAsset"/>
</Web>

Save the file, and then rerun SPMetal using the following command line (as before, this command should be entered on one line):

%SPROOT%\bin\spmetal.exe /web:http://localhost/Chapter14/ →
customertemplate /code:HireSample.cs /parameters:SPMetalParameters.xml

If you now examine HireSample.cs, you’ll notice that the objects have been renamed as specified in the parameters file. Figure 4 shows the new object model.

Figure 4. Revised entity class diagram

3.4 Incorporate a Build Script to Regenerate Entities Automatically

Rather than having to rerun SPMetal manually each time your data structure changes, you can incorporate a build script into your Visual Studio project that calls SPMetal automatically each time the project is built.

In Visual Studio, in the Project menu, select LinqSampleApplication Properties. In the Properties pane, select Build Events, and then click the Edit Pre-Build button. In the dialog that appears, enter the following script (in one continuous line; line breaks are added here for readability):

%SPROOT%\bin\spmetal.exe /web:http://localhost/Chapter14/customertemplate→
/code:"$(ProjectDir)HireSample.cs"→
/parameters:"$(ProjectDir)SPMetalParameters.xml"

Build the project. You’ll notice that when the build has completed, you’re notified that HireSample.cs has been modified. This confirms that the prebuild script has automatically regenerated the file as part of the build process.

 
Others
 
- LINQ to SharePoint and SPMetal : Demonstration Scenario (part 6) - Creating Entities Using SPMetal - Generate Entity Classes
- LINQ to SharePoint and SPMetal : Demonstration Scenario (part 5) - Creating Entities Using SPMetal - Create a Windows Forms Sample Application
- LINQ to SharePoint and SPMetal : Demonstration Scenario (part 4) - Create a Data Structure Using SharePoint 2010 - Associate Content Types , Defining Relationships
- LINQ to SharePoint and SPMetal : Demonstration Scenario (part 3) - Create a Data Structure Using SharePoint 2010 - Create Content Types, Create Customer Template Site
- LINQ to SharePoint and SPMetal : Demonstration Scenario (part 2) - Create a Data Structure Using SharePoint 2010 - Create Site Columns
- LINQ to SharePoint and SPMetal : Demonstration Scenario (part 1)
- LINQ to SharePoint and SPMetal : LINQ to SharePoint
- LINQ to SharePoint and SPMetal : Overview of LINQ
- Microsoft Lync Server 2010 : Virtualization Overview (part 3) - Lync Support Guidelines
- Microsoft Lync Server 2010 : Virtualization Overview (part 2) - Benefits of Virtualization, Virtualization Vendors
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us