IQueryWhereBuilder.WhereIsNull(string left) Method
.NET Standard 2.x
Creates a WHERE clause, and adds a search condition to the WHERE clause. Uses IS NULL
operator to search for values that are null.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
IQueryAndOrBuilder<TModel> WhereIsNull(string left);
Parameters
left
System.String
A SQL expression on the left of the IS NULL
operator.
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 WhereIsNull method to specify that data retrieved from the "Person" table must have a null value for HireDate.
using Appeon.ApiDoc.Models.School;
using SnapObjects.Data;
using System;
using System.Threading.Tasks;
namespace Appeon.ApiDoc.IQueryWhereBuilderExamples
{
public class WhereIsNullExample
{
private SchoolContext _context;
public WhereIsNullExample(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 HireDate is empty.
Builder.WhereIsNull("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: 2
FirstName: Gytis
LastName: Barzdukas
HireDate:
EnrollmentDate: 9/1/2005 12:00:00 AM
Discriminator: Student
*/
}
}
}
Example Refer To
Model Class: Person
Applies to
.NET Standard
2.x