IDataStore.FirstOrDefault<TModel>() Method
.NET Standard 2.x
Generic method. Returns the first data row of the DataStore. If no data row is found, returns null
.
Namespace: DWNet.Data
Assembly: DWNet.Data.dll
Syntax
public TModel FirstOrDefault<TModel>();
Type Parameters
TModel
The type of a model
class that matches with the current DataObject
.
Returns
TModel
Returns the TModel
object which contains the data for the first row.
Returns null
if no row is found.
Examples
The following code example demonstrates how to use the FirstOrDefault
method to get the first record in DataStore.
using Appeon.ApiDoc.Models;
using DWNet.Data;
using System;
namespace Appeon.ApiDoc.IDataStoreExamples
{
public class FirstOrDefaultExample
{
private readonly SchoolContext _context;
public FirstOrDefaultExample(SchoolContext dataContext)
{
// Sets the data context
_context = dataContext;
}
public void Example1()
{
// Instantiates a DataStore object with datawindow: d_department.
var datastore = new DataStore("d_department", _context);
datastore.Retrieve();
// The first record in the Department table is:
// departmentid=1, name=Engineering
var department = datastore.FirstOrDefault<D_Department>();
Console.WriteLine("Department ID: {0}; Department Name: {1}",
department.Departmentid,
department.Name);
/*This code produces the following output:
Department ID: 1; Department Name: Engineering
*/
}
}
}
Example Refer To
Model Class: D_Department
DataWindow File: d_department
Applies to
.NET Standard
2.x