Show / Hide Table of Contents

    IDataStoreBase.RetrieveByKey(params object[] arguments) Method

    .NET Standard 2.x

    Retrieves rows from the database. You can specify a value for a property with the [Key] attribute to retrieve rows to the DataStore.

    Namespace: DWNet.Data

    Assembly: DWNet.Data.dll

    Syntax

      public int RetrieveByKey(params object[] arguments);
    

    Pararmeters

    arguments System.Object[]

    The value for the property with the [Key] attribute.

    Returns

    System.Int32

    Returns the number of rows retrieved (that is, rows in the primary buffer) if it succeeds, otherwise 0.

    This method always returns -1 if the data source is external. Use a method such as ImportJson to populate the DataStore.

    Remarks

    After rows are retrieved, the DataStore's filter is applied. Therefore, any retrieved rows that do not meet the filter criteria are immediately moved to the filter buffer and are not included in the return count.

    Before you can retrieve rows for the DataStore, you must specify a DataContext object with the constructor of DataStore or SetDataContext method to establish a database connection.

    Normally, when you call the Retrieve method, any rows that are already in the DataStore are discarded and replaced with the retrieved rows. You can set DwRetrieveEventArgs.IsResetBuffer to false in the RetrieveStart event to prevent this. In this case, Retrieve adds any retrieved rows to the ones that already exist in the buffers.

    Examples

    The following code example demonstrates how to retrieve rows by key from the database for DataStore.

    using Appeon.ApiDoc.Models;
    using DWNet.Data;
    using System;
    
    namespace Appeon.ApiDoc.IDataStoreBaseExamples
    {
        public class RetrieveByKeyExample
        {
            private readonly SchoolContext _context;
    
            public RetrieveByKeyExample(SchoolContext dataContext)
            {
                // Sets the data context
                _context = dataContext;
            }
    
            public void Example()
            {
                // Instantiates a DataStore object with datawindow: d_department.
                var datastore = new DataStore("d_department", _context);
    			
    			// Retrieves rows by key (DepartmentId = 1).
                datastore.RetrieveByKey(1);
    			
    			// Gets the first row of data from the DataStore.
                var department = datastore.GetModel<D_Department>(0);
    
                Console.WriteLine("Rowcount: {0}", datastore.RowCount);
                Console.WriteLine("DepartmentID: {0}; Name: {1}; Budget: {2}",
                      department.Departmentid, department.Name, department.Budget);
    
                /*This code produces the following output:
                 
                Rowcount: 1
                DepartmentID: 1; Name: Engineering; Budget: 350000.0000
                */
            }
        }
    }
    

    Example Refer To

    Model Class: D_Department
    DataWindow File: d_department

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon