Table of Contents

Method CreateView

Namespace
YndigoBlue.Velocity.Engine
Assembly
YndigoBlue.Velocity.dll

CreateView(View)

Creates a database view based on a query.

public void CreateView(View view)

Parameters

view View

The View object defining the view to create.

Examples

using (var m = new Manager(conn))
{
    var schema = m.LoadSchema("app");
    var usersTable = schema["users"];

    // Create a query for the view
    var query = new Query()
        .Select([usersTable["id"], usersTable["name"], usersTable["email"]])
        .From(usersTable)
        .Where(new Criterion<bool>(usersTable["active"], ConditionalType.Equals, true));

    // Create the view
    var view = new View(schema, "active_users", query);
    m.CreateView(view);
}

Exceptions

DbException

Thrown when a database error occurs or if the view already exists.

CreateView(View, bool)

Creates a database view based on a query, optionally overwriting if it exists.

public void CreateView(View view, bool overwrite)

Parameters

view View

The View object defining the view to create.

overwrite bool

If true, drops and recreates the view if it exists; if false, throws an error if it exists.

Examples

using (var m = new Manager(conn))
{
    var schema = m.LoadSchema("app");
    var ordersTable = schema["orders"];

    var query = new Query()
        .Select([
            ordersTable["customer_id"],
            new Aggregate("total_sales", ordersTable["total"], AggregateType.Sum)
        ])
        .From(ordersTable)
        .GroupBy([ordersTable["customer_id"]]);

    var view = new View(schema, "customer_sales", query);
    m.CreateView(view, overwrite: true);
}

Exceptions

DbException

Thrown when a database error occurs.