IDataStore.LastOrDefault<TModel>() Method
.NET Standard 2.x
Generic method. Returns the last data row of the DataStore. If no data row is found, returns null
.
Namespace: DWNet.Data
Assembly: DWNet.Data.dll
Syntax
public TModel LastOrDefault<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 of the last row; and returns null
if no row is found.
Examples
The following code example demonstrates how to use the LastOrDefault
method to get the last record object in DataStore.
using Appeon.ApiDoc.Models;
using DWNet.Data;
using System;
namespace Appeon.ApiDoc.IDataStoreExamples
{
public class LastOrDefaultExample
{
private readonly SchoolContext _context;
public LastOrDefaultExample(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 last record in the Department table is:
// departmentid = 7, name = Mathematics
var department = datastore.LastOrDefault<D_Department>();
Console.WriteLine("Department ID: {0}; Department Name: {1}",
department.Departmentid, department.Name);
/*This code produces the following output:
Department ID: 7; Department Name: Mathematics
*/
}
}
}
Example Refer To
Model Class: D_Department
DataWindow File: d_department
Applies to
.NET Standard
2.x