Show / Hide Table of Contents

    SqlBuilder.Delete(string table, string schema) 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 and the schema 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, string schema);
    

    Parameters

    table System.String

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

    schema System.String

    The name of the corresponding schema for the table.

    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 ISqlDeleteBuilder Delete(string table, string schema) method.It builds a SQL DELETE statement to delete the records whose name="English" from the "Department" table and specifies the schema for 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 Example2()
            {
                // Builds a SQL DELETE statement to specify a schema and delete records whose name="English" from the "Department" table. 
                var delete = SqlBuilder.Delete("Department", "dbo")
                    .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 [dbo].[Department]
                WHERE ([name] = N'English')    
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon