IDwMeta.CreateFromSql(ISqlQueryBuilder sqlBuilder, DataContext context) Method
.NET Standard 2.x
Creates an IDwMeta
object using the SQL statement built by the ISqlQueryBuilder
object.
Namespace: DWNet.Data
Assembly: DWNet.Data.dll
Syntax
public static IDwMeta CreateFromSql(ISqlQueryBuilder sqlBuilder, DataContext context);
Parameters
sqlBuilder
SnapObjects.Data.ISqlQueryBuilder
An ISqlQueryBuilder
object used to build a SQL SELECT statement.
context
SnapObjects.Data.DataContext
A DataContext
object which represents the entry to the database.
Returns
The new IDwMeta
object created based on the specified SQL builder object and DataContext.
Examples
The following code example demonstrates how to use the CreateFromSql
method to create a DwMeta
object from a SQL Query Builder.
using DWNet.Data;
using SnapObjects.Data;
using System;
namespace Appeon.ApiDoc.IDwMetaExamples
{
public class CreateFromSqlExample
{
private readonly SchoolContext _context;
public CreateFromSqlExample(SchoolContext dataContext)
{
// Sets the data context
_context = dataContext;
}
public void Example2()
{
// Defines a SQL Query Builder.
var queryBuilder = new SqlQueryBuilder();
queryBuilder.Select("DepartmentId")
.Select("Name")
.Select("Budget")
.From("Department", null, "dbo");
// Creates a DwMeta object
IDwMeta dwMeta = DwMeta.CreateFromSql(queryBuilder, _context);
// Creates a DataStore from DwMeta.
IDataStore ds = DataStore.Create(dwMeta, _context);
// Gets the properties of the Columns.
var columnMetas = ds.DwMeta.Columns;
Console.WriteLine("Columns Count: {0}", columnMetas.Count);
// Gets the zero-based ID of the column.
for (int i = 0; i < columnMetas.Count; i++)
{
Console.WriteLine("Column Name: {0}; ID: {1}",
columnMetas[i].Name, columnMetas[i].ID);
}
/*This code produces the following output:
Columns Count: 3
Column Name: DepartmentId; ID: 0
Column Name: Name; ID: 1
Column Name: Budget; ID: 2
*/
}
}
}
Applies to
.NET Standard
2.x