IQueryAndOrBuilder<TModel>.OrWhere(ISqlWhereCondition condition) Method
.NET Standard 2.x
Adds the OR
logical operator and a search condition (specified by an ISqlWhereCondition
object) to the WHERE clause.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
IQueryAndOrBuilder<TModel> OrWhere(ISqlWhereCondition condition);
Parameters
condition
SnapObjects.Data.ISqlWhereCondition
An ISqlWhereCondition
which represents a search condition for WHERE clause.
This object can be created by using the SqlBuilder.Where
method and so on.
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 OrWhere method to add an OR condition to the WHERE clause. In this example, the OR condition is specified by the variable for another WHERE clause.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Appeon.ApiDoc.Models.School;
using SnapObjects.Data;
namespace Appeon.ApiDoc.IQueryAndOrBuilderExamples
{
public class OrWhereExample
{
private SchoolContext _context;
public OrWhereExample(SchoolContext dataContext)
{
// Sets Data Context
_context = dataContext;
}
public async Task<int> Example7()
{
// Get a QueryBuilder.
var Builder = _context.SqlModelMapper.GetQueryBuilder<Person>();
// Defines a SqlWhereCondition.
var sqlwherebuilder = SqlBuilder.Where("PersonID", SqlBinaryOperator.Equals,
SqlBuilder.Parameter<int>("id"));
var sqlwherebuilder2 = SqlBuilder.Where("PersonID", SqlBinaryOperator.Equals,
SqlBuilder.Parameter<int>("id2"));
Builder.Where(sqlwherebuilder)
.OrWhere(sqlwherebuilder2);
var result = (await Builder.LoadAsync(1, 2)).ToList();
foreach (var person in result)
{
Console.WriteLine("PersonID: {0}", person.PersonID);
Console.WriteLine("FirstName: {0}", person.FirstName);
Console.WriteLine("LastName: {0}", person.LastName);
Console.WriteLine();
}
return result.Count;
/*This code produces the following output:
PersonID: 1
FirstName: Kim
LastName: Abercrombie
PersonID: 2
FirstName: Gytis
LastName: Barzdukas
*/
}
}
}
Example Refer To
Model Class: Person
Applies to
.NET Standard
2.x