IT tutorials
 
Technology
 

LINQ to SharePoint and SPMetal : Adding Data Using LINQ (part 2) - Add On-Hire Assets,Add AssetNotes

11/26/2013 8:26:27 PM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
Add On-Hire Assets

Now that we have documents in our document library, we can move on and create list items that refer to those documents. Double-click the Add On-Hire Assets button on the form designer to add an on-click event handler. Add the following code:

private void button2_Click(object sender, EventArgs e)
{
//Add some assets for our contracts
//disable the button to prevent concurrency problems
button2.Enabled = false;
using(HireSampleDataContext dxWrite = new HireSampleDataContext(SiteUrl.Text))
{
//since we'll be making changes, we must set ObjectTrackingEnabled to true
//This is the default value but is explicitly included here
//for the sake of clarity
dxWrite.ObjectTrackingEnabled=true;
int counter = 0;
//loop through the contracts in our Hire Contracts document library
foreach (HireContract contract in dxWrite.HireContracts)
{
//Add new assets for each contract
for (int x = 0; x < 3; x++)
{
OnHireAsset newAsset = new OnHireAsset();

//generate sequential sample data
newAsset.AssetId = counter.ToString("ASSET000");
newAsset.AssetTag = counter.ToString("TAG-000");
newAsset.ContractReference = contract;
//set the new asset entity to be added into the OnHireAssets list
dxWrite.OnHireAssets.InsertOnSubmit(newAsset);
counter++;
}
}

//Submit the changes. This will actually add the items to the list
dxWrite.SubmitChanges();
}
//change the text on the button so that we know the job's done
button2.Text += " - Done";
}



Notice first, and most importantly, that everything is strongly typed, meaning that if the code contained any errors, it would not compile. Second, the code is much more descriptive than the preceding example. It’s apparent which data entities we’re dealing with and what actions we’re performing on them purely from the syntax of the code. Finally, each On-Hire Asset must have an associated Hire Contract. In this code, the assignment of a parent Hire Contract is done by simply assigning an appropriate HireContract entity to the ContractReference property that defines the relationship. There’s no need to know exactly which field is used to define the foreign key since all of that information is automatically determined by the configuration of the lookup field.

Add AssetNotes

We’ve created sample contracts and associated assets; the next thing to add is Asset Notes for each asset. Double-click the Add Asset Notes button to add an on-click event handler. Add the following code:

private void button3_Click(object sender, EventArgs e)
{
//disable the button to prevent concurrency problems
button3.Enabled = false;

//Add some notes for our sample assets
using(HireSampleDataContext dxWrite = new HireSampleDataContext(SiteUrl.Text))
{
dxWrite.ObjectTrackingEnabled = true;
foreach (OnHireAsset asset in dxWrite.OnHireAssets)
{
for (int x = 0; x < 3; x++)
{
AssetNote newNote = new AssetNote();

newNote.LocationCode = x.ToString("Location000");
newNote.AssetReference = asset;
dxWrite.AssetNotes.InsertOnSubmit(newNote);
}
}
dxWrite.SubmitChanges();
}
//change the text on the button so that we know the job's done
button3.Text += " - Done";
}



You should now have a Windows Forms application with three buttons that can be used to generate some sample data. Run the application, clicking each of the three buttons in turn to add some sample data.

 
Others
 
- LINQ to SharePoint and SPMetal : Adding Data Using LINQ (part 1) - Add Data Generation Buttons to LinqSampleApplication , Add Sample Contracts
- Windows 7 : Kernel Mode Installation and Build - Using WinDbg with Featured Toaster, Versioning and Dynamic Binding
- Windows 7 : Kernel Mode Installation and Build - Debugging Macros and Routines, WDF Debugger Extension Commands
- Microsoft Excel 2010 : Introducing the Excel Web App - Sharing a Workbook, Interacting with a Sheet Online
- Microsoft Excel 2010 : Uploading and Downloading Workbooks (part 2) - Saving to SkyDrive from Excel, Saving a File to Your Local Drive
- Microsoft Excel 2010 : Uploading and Downloading Workbooks (part 1) - Accessing the SkyDrive, Uploading with Windows Live
- Microsoft Excel 2010 : Introducing the Excel Web App - Acquiring a Windows Live ID
- Deploying Windows in a Windows Server 2008 R2 Environment (part 6) - Practice Create a Windows PE CD
- Deploying Windows in a Windows Server 2008 R2 Environment (part 5) - Windows Deployment Methods - Windows Deployment Services
- Deploying Windows in a Windows Server 2008 R2 Environment (part 4) - Windows Deployment Methods - Installing from the Product DVD, Network Share Distribution
 
 
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