IT tutorials
 
Technology
 

LINQ to SharePoint and SPMetal : Deleting Data Using LINQ (part 1) - Deleting Sample Data

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

Although we couldn’t use LINQ to add document items to a document library, we can use LINQ to delete such items. Delete works because LINQ provides a DeleteOnSubmit method that makes use of the unique identifier for the entity object to delete the corresponding object from the data store.

1. Deleting Sample Data

Add a new button to the sample application and name it Delete Sample Data.

Add the following code in the on-click event handler:

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

using(HireSampleDataContext dxWrite = new HireSampleDataContext(SiteUrl.Text))
{
dxWrite.ObjectTrackingEnabled = true;
//loop through the Hire Contracts
foreach (HireContract contract in dxWrite.HireContracts)
{
//for each contract, loop through the assets
foreach (OnHireAsset asset in contract.OnHireAsset)
{
//for each asset loop through the notes
foreach (AssetNote note in asset.AssetNote)
{
//delete the note
dxWrite.AssetNotes.DeleteOnSubmit(note);
}
//delete the asset
dxWrite.OnHireAssets.DeleteOnSubmit(asset);
}
//finally delete the contract
dxWrite.HireContracts.DeleteOnSubmit(contract);
}

dxWrite.SubmitChanges();
}

//change the text on the button so that we know the job's done
button4.Text += " - Done";
}



It should be apparent from the comments that this code will delete all the sample data that we created in the preceding code examples. It uses three nested loops to ensure that referential integrity is maintained, and all associated child data is deleted before the parent element is deleted.

 
Others
 
- LINQ to SharePoint and SPMetal : Adding Data Using LINQ (part 2) - Add On-Hire Assets,Add AssetNotes
- 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
 
 
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