Show / Hide Table of Contents

    SqlBuilder.Delete(string table) Method

    .NET Standard 2.x | Current Version (1.0.1)

    0.5.0-alpha

    1.0.1 (current)

    Creates an ISqlDeleteBuilder object for building the SQL DELETE statement, and specifies the name of the table or view from which the rows are to be removed.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

      public static ISqlDeleteBuilder Delete(string table);
    

    Parameters

    table System.String

    The name of the table or view from which the rows are to be removed.

    Returns

    SnapObjects.Data.ISqlDeleteBuilder

    Returns a newly created ISqlDeleteBuilder object which can be used to build the SQL DELETE statement.

    Remarks

    If no DELETE condition is specified, all of the records will be deleted from the table.

    Examples

    The following code example demonstrates how to use the Delete(string table) method. It builds a SQL DELETE statement to delete the records whose name="English" from the "Department" table.

    using SnapObjects.Data;
    using System;
    
    namespace Appeon.ApiDoc.SqlBuilderExamples
    {
        public class DeleteExample
        {
            private SchoolContext _context;
    
            public DeleteExample(SchoolContext dataContext)
            {
                // Sets Data Context.
                _context = dataContext;
            }
    
            public void Example1()
            {
                // Builds a SQL DELETE statement to delete the records whose name="English" from the "Department" table.      
                var delete = SqlBuilder.Delete("Department")
                    .WhereValue("name", SqlBinaryOperator.Equals, "English");
    
                // Converts to raw SQL for the database corresponding to the data context.
                string sql = delete.ToSqlString(_context);
    
                Console.WriteLine(sql);
    
                /*This code produces the following output:
                
                DELETE
                FROM [Department]
                WHERE ([name] = N'English')     
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon