IDwMeta.CreateFromSql(string sqlSyntax, DataContext context, params ISqlParameter[] parameters) Method
.NET Standard 2.x
Creates an IDwMeta object using a raw SQL.
Namespace: DWNet.Data
Assembly: DWNet.Data.dll
Syntax
public static IDwMeta CreateFromSql(string sqlSyntax, DataContext context, params ISqlParameter[] parameters);
Parameters
sqlSyntax System.String
The SQL SELECT statement used to create the IDwMeta object.
context SnapObjects.Data.DataContext
A DataContext object which represents the entry to the database.
parameters SnapObjects.Data.ISqlParameter[]
(Optional) An array of ISqlParameter objects which defines the SQL parameters used in the raw SQL.
Returns
The new IDwMeta object created based on the specified SQL syntax and DataContext.
Examples
The following code example demonstrates how to use the CreateFromSql method to create a DwMeta object from a raw SQL Select statement.
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 Example1()
{
// Defines a SQL Select statement.
string sql = "SELECT DepartmentId, Name FROM dbo.Department";
// Creates a DwMeta object.
var dwMeta = DwMeta.CreateFromSql(sql, _context);
// Creates a DataStore from DwMeta.
var 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: 2
Column Name: DepartmentId; ID: 0
Column Name: Name; ID: 1
*/
}
}
}
Applies to
.NET Standard
2.x