IQueryWhereBuilder.WhereRaw(string whereClause, params ISqlParameter[] parameters) Method
.NET Standard 2.x
Creates a WHERE clause, and adds a raw SQL to the WHERE clause.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
IQueryAndOrBuilder<TModel> WhereRaw(string whereClause, params ISqlParameter[] parameters);
Parameters
whereClause
System.String
A string of raw SQL to be added to the WHERE clause.
parameters
SnapObjects.Data.ISqlParameter[]
(Optional) An array of ISqlParameter
objects which defines the SQL parameters used in the raw SQL.
Returns
Returns an IQueryAndOrBuilder<TModel>
object which can be used to add more search conditions to the current WHERE clause.
Examples
The following code example uses the WhereRaw method to build the WHERE condition in a raw SQL.
using Appeon.ApiDoc.Models.School;
using SnapObjects.Data;
using System;
using System.Threading.Tasks;
namespace Appeon.ApiDoc.IQueryWhereBuilderExamples
{
public class WhereRawExample
{
private SchoolContext _context;
public WhereRawExample(SchoolContext dataContext)
{
// Sets Data Context
_context = dataContext;
}
public async Task<int> Example()
{
// Get a QueryBuilder.
var Builder = _context.SqlModelMapper.GetQueryBuilder<Department>();
// Creates a WHERE clause, and adds a raw SQL to the WHERE clause.
Builder.WhereRaw("DepartmentID = :id", SqlBuilder.Parameter<int>("id"));
var result = (await Builder.LoadAsync(4)).FirstOrDefault();
Console.WriteLine("DepartmentID: {0}", result.DepartmentID);
Console.WriteLine("Name: {0}", result.Name);
Console.WriteLine("Budget: {0}", result.Budget);
Console.WriteLine("Administrator: {0}", result.Administrator);
Console.WriteLine("StartDate: {0}", result.StartDate);
return result.DepartmentID;
/*This code example produces the following output:
DepartmentID: 4
Name: Economics
Budget: 200000.0000
Administrator: 4
StartDate: 9/1/2007 12:00:00 AM
*/
}
}
}
Example Refer To
Model Class: Department
Applies to
.NET Standard
2.x