IQueryAndOrBuilder<TModel>.AndWhereRaw(string clause, params ISqlParameter[] parameters) Method
.NET Standard 2.x
Adds the AND
logical operator and a raw SQL to the WHERE clause.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
IQueryAndOrBuilder<TModel> AndWhereRaw(string clause, params ISqlParameter[] parameters);
Parameters
clause
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 define the SQL parameters used in the raw SQL.
Returns
Returns anIQueryAndOrBuilder<TModel>
object which can be used to add more search conditions to the current WHERE clause.
Examples
The following code example demonstrates how to use the AndWhereRaw method to add an AND condition (in raw SQL) to the WHERE clause.
using Appeon.ApiDoc.Models.School;
using SnapObjects.Data;
using System;
using System.Threading.Tasks;
namespace Appeon.ApiDoc.IQueryAndOrBuilderExamples
{
public class AndWhereRawExample
{
private SchoolContext _context;
public AndWhereRawExample(SchoolContext dataContext)
{
// Sets Data Context
_context = dataContext;
}
public async Task<int> Example()
{
// Get a QueryBuilder.
var Builder = _context.SqlModelMapper.GetQueryBuilder<Department>();
Builder.WhereRaw("DepartmentID = :id", SqlBuilder.Parameter<int>("id"))
.AndWhereRaw("Name = :name", SqlBuilder.Parameter<string>("name"));
var result = (await Builder.LoadAsync(4, "Economics")).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