Show / Hide Table of Contents

    IDataStoreBase.Validate() Method

    .NET Standard 2.x

    Verifies the data using the data validation rules set in the DataStore.

    Namespace: DWNet.Data

    Assembly: DWNet.Data.dll

    Syntax

      public bool Validate();
    

    Returns

    System.Boolean

    Returns true if all data meet the validation rule; false if any data does not meet the validation rule.

    Examples

    The following code example specifies the validation rule (budget is greater than 0), and then modifies one of the budget values to a negative value. The Validate method will return false if any data does not meet the rule.

    using DWNet.Data;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    
    namespace Appeon.ApiDoc.IDataStoreBaseExamples
    {
        public class ValidateExample
        {
            private readonly SchoolContext _context;
    
            public ValidateExample(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);
    
                // Retrieves rows from the database for datastore
                datastore.Retrieve();
    
                // Sets the validation rule with the third column: 
                // value for budget must be greater than 0.
                datastore.SetValidate(2, "budget > 0");
    
                // Sets the vaue for budget in row 1 to -350000.
                datastore.SetItem(0, "budget", -350000m);
    
                // If all data passes validation, commit data to database, 
                // otherwise, display an error.
                if (datastore.Validate())
                {
                    datastore.Update();
                }
                else
                {
                    Console.WriteLine("Invalid data! Please check!");
                }
    
                /*This code produces the following output:
                
                Invalid data! Please check!
                */
            }
        }
    }
    

    Example Refer To

    Model Class: D_Department
    DataWindow File: d_department

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon