Show / Hide Table of Contents

    ISqlFromBuilder.AsJoin() Method

    .NET Standard 2.x

    Returns an ISqlJoinOnAndOr object which Represents an object used to build the JOIN clause of a SQL statement.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

      ISqlJoinOnAndOr AsJoin();
    

    Returns

    SnapObjects.Data.ISqlJoinOnAndOr

    Returns the ISqlJoinOnAndOr object which can be used to build the JOIN clause of a SQL statement (e.g. adding search conditions to the JOIN clause).

    Examples

    The following code example demonstrates how to use the AsJoin() method to get the existing JOIN condition and add a condition to it.

    using SnapObjects.Data;
    using System;
    
    namespace Appeon.ApiDoc.ISqlFromBuilderExamples
    {
        public class AsJoinExample
        {
            private SchoolContext _context;
    
            public AsJoinExample(SchoolContext dataContext)
            {
                // Sets the Data Context
                _context = dataContext;
            }
    
            public void Example()
            {
    
                // Declares SqlQueryBuilder.
                var sqlbuilder = new SqlQueryBuilder();
    
                // Defines a SQL statement with JOIN.
                sqlbuilder.Select("d.name")
                    .Select("c.title")
                    .From("Department", "d")
                    .Join("Course", "c")
                    .OnRaw("d.DepartmentID = c.DepartmentID")
                    .WhereRaw("c.Credits = 4");
    
                // Gets the JOIN condition and adds another condition: Department.budget > 300000.
                sqlbuilder.AsJoin().AndOnRaw("d.budget > 300000");
    
                // 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:
                
                SELECT
                [d].[name],
                [c].[title]
                FROM [Department] AS [d] JOIN [Course] AS [c]
                ON [d].[DepartmentID] = [c].[DepartmentID]
                AND [d].[budget] > 300000
                WHERE ([c].[Credits] = 4)
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon