Show / Hide Table of Contents

    IDataStore.GetForUpdate<TModel>(Predicate<TModel> predicate) Method

    .NET Standard 2.x

    Obtains a TModel object for update according to the specified condition.

    Namespace: DWNet.Data

    Assembly: DWNet.Data.dll

    Syntax

     public TModel GetForUpdate<TModel>(Predicate<TModel> predicate);
    

    Parameters

    predicate System.Predicate<TModel>

    A Predicate<TModel> that you want to use as the search criteria.

    Returns

    System.Int32

    Returns the TModel object which contains the data for the row found.

    It returns null if no row is found.

    Remarks

    This method makes a shallow copy of the data, therefore, any changes made to this TModel will affect the data source. To make a deep copy of the data, refer to GetModel. If multiple rows satisfy the condition, the first row will be returned.

    The index number starts from 0, which is consistent with C#.

    Examples

    The following code example demonstrates how to get data from a Predicate<TModel> object.

    using Appeon.ApiDoc.Models;
    using DWNet.Data;
    using System;
    
    namespace Appeon.ApiDoc.IDataStoreExamples
    {
        public class GetForUpdateExample
        {
            private readonly SchoolContext _context;
    
            public GetForUpdateExample(SchoolContext dataContext)
            {
                // Sets the data context
                _context = dataContext;
            }
    
            public void Example2()
            {
                // Instantiates a DataStore object with datawindow: d_department.
                var datastore = new DataStore("d_department", _context);
    
                datastore.Retrieve();
    
                var department = datastore.GetForUpdate<D_Department>(a => a.Departmentid == 1);
    
                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

    Back to top Generated by Appeon