Show / Hide Table of Contents

    ISqlUpdateBuilder.Set(string columnName, ISqlBuilder queryBuilder) Method

    .NET Standard 2.x

    Specifies the value of a column to be updated with a SQL subquery (specified by an ISqlBuilder object).

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

      ISqlUpdateBuilder Set(string columnName, ISqlBuilder queryBuilder);
    

    Parameters

    columnName System.String

    The name of the column to be updated.

    queryBuilder SnapObjects.Data.ISqlBuilder

    An ISqlBuilder object which represents a SQL subquery.

    Returns

    SnapObjects.Data.ISqlUpdateBuilder

    Returns the current ISqlUpdateBuilder object.

    Examples

    The following code example demonstrates how to use the Set(string columnName, ISqlBuilder queryBuilder) method.It modifies the value of the "URL" column for the record whose courseid=2030 in the "OnlineCourse" table using the value returned by a subquery.

    using SnapObjects.Data;
    using System;
    
    namespace Appeon.ApiDoc.ISqlUpdateBuilderExamples
    {
        public class SetExample
        {
            private SchoolContext _context;
    
            public SetExample(SchoolContext dataContext)
            {
                // Sets Data Context.
                _context = dataContext;
            }
    
            public void Example3()
            {
    
                // Declares SqlQueryBuilder.
                var sqlbuilder = new SqlUpdateBuilder();
                var subQuery = new SqlQueryBuilder();
    
                // Defines the subquery statement.
                subQuery.Select("url")
                    .From("OnlineCourse")
                    .Where("courseid","2021");
    
                // Updates the record where courseid=2030 in the OnlineCourse table.
                // Modifies the value of the "URL" column using the value returned by a subquery.
                sqlbuilder.Update("OnlineCourse")
                       .Set("url", subQuery)
                       .Where("courseid", "2030");
    
    
                // Converts to raw SQL for the database corresponding to the data context.
                string sql = sqlbuilder.ToSqlString(_context);
    
                Console.WriteLine(sql);
                
                /*This code produces the following output:
                
                UPDATE [OnlineCourse] SET [url] = (SELECT
                [url]
                FROM [OnlineCourse]
                WHERE ([courseid] = 2021))
                WHERE ([courseid] = 2030)
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon