Show / Hide Table of Contents

    ISqlModelMapper.TrackSqlBuilder(ISqlDeleteBuilder deleteBuilder, params object[] parameters) Method

    .NET Standard 2.x

    Tracks a database table delete operation. A SQL DELETE statement will be generated using the specified ISqlDeleteBuilder object. When ISqlModelMapper.SaveChanges method is called, the SQL DELETE statement will be executed.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

      public ISqlModelMapper TrackSqlBuilder(ISqlDeleteBuilder deleteBuilder, params object[] parameters);
    

    Parameters

    deleteBuilder SnapObjects.Data.ISqlDeleteBuilder

    An interface used to build the SQL DELETE statement.

    parameters System.Object[]

    (Optional) One or more values that you want to use as arguments in the DELETE SQL statement defined in deleteBuilder.

    Returns

    SnapObjects.Data.ISqlModelMapper

    Returns an ISqlModelMapper object, which can be used for executing other methods.

    Examples

    The following code example demonstrates how to delete a student.

    using SnapObjects.Data;
    using System;
    
    namespace Appeon.ApiDoc.ISqlModelMapperExamples
    {
        public class TrackSqlBuilderExample
        {
            private SchoolContext _context;
    
            public TrackSqlBuilderExample(SchoolContext dataContext)
            {
                // Sets the data context.
                _context = dataContext;
            }
    
            public void Example2()
            {
    
                var deleteBuilder = new SqlDeleteBuilder();
    
                // Builds a SQL Delete statement with no parameters to delete a student.
                deleteBuilder.Delete("Person")
                            .From("Person")
                            .Where("LastName", "'Senior'")
                            .AndWhere("FirstName", "'Letitia'");
    
                Console.WriteLine("SQL Delete statement is:");
                Console.WriteLine(deleteBuilder.ToSqlString(_context));
    
                // Tracks the SQL Delete statement and executes it in the database.
                var dbResult = _context.SqlModelMapper.TrackSqlBuilder(deleteBuilder)
                                                   .SaveChanges();
    
                /* The code produces the following output:
                SQL Delete statement is:
                DELETE [Person]
                FROM [Person]
                WHERE ([LastName] = 'Senior'
                AND [FirstName] = 'Letitia')
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon