Table of Contents

Method CreateView

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

CreateView(View, bool)

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

public void CreateView(View view, bool overwrite = false)

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 Expression("total_sales", new Aggregate(AggregateType.Sum, ordersTable["total"]))
        ])
        .From(ordersTable)
        .GroupBy(ordersTable["customer_id"]);

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

Exceptions

DbException

Thrown when a database error occurs.