IQueryAndOrBuilder<TModel>.AndWhereIsNotNull(string left) Method
.NET Standard 2.x
Adds the AND
logical operator and a search condition to the WHERE clause; and uses IS NOT NULL
operator to search for values that are not null.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
IQueryAndOrBuilder<TModel> AndWhereIsNotNull(string left);
Parameters
left
System.String
A SQL expression on the left of the IS NOT NULL
operator.
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 AndWhereIsNotNull method to add an AND IS NOT NULL condition to the WHERE clause. In this example, the IS NOT NULL condition specifies that the HireDate value cannot be null.
using Appeon.ApiDoc.Models.School;
using SnapObjects.Data;
using System;
using System.Threading.Tasks;
namespace Appeon.ApiDoc.IQueryAndOrBuilderExamples
{
public class AndWhereIsNotNullExample
{
private SchoolContext _context;
public AndWhereIsNotNullExample(SchoolContext dataContext)
{
// Sets Data Context
_context = dataContext;
}
public async Task<int> Example()
{
// Get a QueryBuilder.
var Builder = _context.SqlModelMapper.GetQueryBuilder<Person>();
// Defines a WHERE condition that the column of EnrollmentDate is not empty.
Builder.WhereIsNotNull("EnrollmentDate")
.AndWhereIsNotNull("HireDate");
var result = (await Builder.LoadAsync()).FirstOrDefault();
if (result != null)
{
Console.WriteLine("PersonID: {0}", result.PersonID);
Console.WriteLine("FirstName: {0}", result.FirstName);
Console.WriteLine("LastName: {0}", result.LastName);
Console.WriteLine("HireDate: {0}", result.HireDate);
Console.WriteLine("EnrollmentDate: {0}", result.EnrollmentDate);
Console.WriteLine("Discriminator: {0}", result.Discriminator);
return result.PersonID;
}
else
{
Console.WriteLine("Not found!");
return 0;
}
/*This code example produces the following output:
PersonID: 3015
FirstName: Chen
LastName: Ward
HireDate: 10/12/1997 12:00:00 AM
EnrollmentDate: 1/1/2019 12:00:00 AM
Discriminator: Student
*/
}
}
}
Example Refer To
Model Class: Person
Applies to
.NET Standard
2.x