ISqlModelMapper.Exists<TModel>(params object[] parameters) Method
.NET Standard 2.x
Checks whether any record exists according to the retrieval criteria specified in a TModel
class.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
public bool Exists<TModel>(params object[] parameters);
Type Parameters
TModel
The type of a model class.
Parameters
parameters
System.Object[]
(Optional) One or more values that you want to use as retrieval arguments in the SQL SELECT statement defined in TModel
.
Returns
System.Boolean
Returns whether any record exists.
Remarks
This method is equivalent to executing the Count method and checking whether its return value is greater than zero (0).
Examples
The following code example demonstrates how to check if a course exists.
using Appeon.ApiDoc.Models.School;
using System;
namespace Appeon.ApiDoc.ISqlModelMapperExamples
{
public class ExistsExample
{
private SchoolContext _context;
public ExistsExample(SchoolContext dataContext)
{
// Sets the data context.
_context = dataContext;
}
public void Example()
{
// Checks if the poetry course exists.
bool hasCourse = _context.SqlModelMapper.Exists<CourseByTitle>("Poetry");
Console.WriteLine("The poetry course exists: {0}.",
hasCourse);
/* The code produces the following output:
The poetry course exists: true.
*/
}
}
}
Example Refer To
Model Class: CourseByTitle
Applies to
.NET Standard
2.x