Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
 DeleteOnSubmit Method

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
Table<(Of <(TEntity>)>)..::.DeleteOnSubmit Method

Puts an entity from this table into a pending delete state.

Namespace:  System.Data.Linq
Assembly:  System.Data.Linq (in System.Data.Linq.dll)
Visual Basic (Declaration)
Public Sub DeleteOnSubmit ( _
    entity As TEntity _
)
Visual Basic (Usage)
Dim instance As Table
Dim entity As TEntity

instance.DeleteOnSubmit(entity)
C#
public void DeleteOnSubmit(
    TEntity entity
)
Visual C++
public:
void DeleteOnSubmit(
    TEntity entity
)
JScript
public function DeleteOnSubmit(
    entity : TEntity
)

Parameters

entity
Type: TEntity
The entity to be deleted.

The removed entity is not seen to be missing from the query results until after SubmitChanges is called. Disconnected entities must first be attached before they can be deleted. For more information, see Data Retrieval and CUD Operations in N-Tier Applications (LINQ to SQL).

NoteNote:

    LINQ to SQL does not support or recognize cascade-delete operations. If you want to delete a row in a table that has constraints against it, you must either set the ON DELETE CASCADE rule in the foreign-key constraint in the database, or use your own code to first delete the child objects that prevent the parent object from being deleted. Otherwise, an exception is thrown.

Visual Basic
' Query the database for the rows to be deleted.
Dim deleteOrderDetails = _
    From details In db.OrderDetails() _
    Where details.OrderID = 11000 _
    Select details

For Each detail As OrderDetail In deleteOrderDetails
    db.OrderDetails.DeleteOnSubmit(detail)
Next

Try
    db.SubmitChanges()
Catch ex As Exception
    Console.WriteLine(ex)
    ' Provide for exceptions
End Try

C#
// Query the database for the rows to be deleted.
var deleteOrderDetails =
    from details in db.OrderDetails
    where details.OrderID == 11000
    select details;

foreach (var detail in deleteOrderDetails)
{
    db.OrderDetails.DeleteOnSubmit(detail);
}

try
{
    db.SubmitChanges();
}
catch (Exception e)
{
    Console.WriteLine(e);
    // Provide for exceptions.
}

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker