Show / Hide Table of Contents

    DwUpdateAttribute Class

    .NET Standard 2.x

    Specifies the method for the insert, delete or update operation.

    Namespace: DWNet.Data

    Assembly: DWNet.Data.dll

    Inheritance Constructor

    System.Attribute

    Syntax

       [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
       public class DwUpdateAttribute : Attribute
    

    Constructors

    Name Description
    DwUpdateAttribute(DwUpdateAction action, string name) Initializes a new instance of the DwUpdateAttribute class.

    Properties

    Name Return Type Description
    Action DwUpdateAction An enumerated value that defines the update, delete, or insert action
    Name string The method for the operation

    Remarks

    This class corresponds to the Stored Procedure Update method defined by DataWindow.

    Examples

    The following code example demonstrates how to use the Model DwUpdate attribute. The example defines DwUpdate(DwUpdateAction.Delete, "dbo.DeletePerson;1"), which means when DataStore performs the Delete operation, it executes the stored procedure dbo.DeletePerson, rather than generating the Delete SQL statement.

    Model: D_Person_With_Deleteaction
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.ComponentModel.DataAnnotations.Schema;
    using SnapObjects.Data;
    using DWNet.Data;
    using Newtonsoft.Json;
    using System.Collections;
    
    namespace Appeon.ApiDoc.Models
    {
        [DataWindow("d_person_with_deleteaction", DwStyle.Grid)]
        [Table("Person")]
        #region DwSelectAttribute  
        [DwSelect("PBSELECT( VERSION(400) TABLE(NAME=\"Person\" ) @(_COLUMNS_PLACEHOLDER_) )")]
        #endregion
        [DwUpdate(DwUpdateAction.Delete, "dbo.DeletePerson;1")]
        [DwUpdateParameter(DwUpdateAction.Delete, DwArgumentSource.Column, "PersonID", "personid", UseOriginal = true, Direction = System.Data.ParameterDirection.Input)]
        [DwKeyModificationStrategy(UpdateSqlStrategy.DeleteThenInsert)]
        [UpdateWhereStrategy(UpdateWhereStrategy.KeyAndConcurrencyCheckColumns)]
        public class D_Person_With_Deleteaction
        {
            [Key]
            [Identity]
            [DwColumn("Person", "PersonID")]
            public int Personid { get; set; }
    
            [ConcurrencyCheck]
            [StringLength(50)]
            [DwColumn("Person", "LastName")]
            public string Lastname { get; set; }
    
            [ConcurrencyCheck]
            [StringLength(50)]
            [DwColumn("Person", "FirstName")]
            public string Firstname { get; set; }
    
            [ConcurrencyCheck]
            [DwColumn("Person", "HireDate")]
            public DateTime? Hiredate { get; set; }
    
            [ConcurrencyCheck]
            [DwColumn("Person", "EnrollmentDate")]
            public DateTime? Enrollmentdate { get; set; }
    
            [ConcurrencyCheck]
            [StringLength(50)]
            [DwColumn("Person", "Discriminator")]
            public string Discriminator { get; set; }
    
        }
    
    }
    
    Example Method:
    using System;
    using DWNet.Data;
    
    namespace Appeon.ApiDoc.DwUpdateAttributeExamples
    {
        public class DwUpdateAttributeExample
        {
            private readonly SchoolContext _context;
    
            public DwUpdateAttributeExample(SchoolContext dataContext)
            {
                // Sets the data context.
                _context = dataContext;
            }
    
            public void Example()
            {
                var datastore = new DataStore("d_person_with_deleteaction", _context);
                datastore.Retrieve();
    			
    			//Deletes the first row from the primary buffer of DataStore.
                datastore.DeleteRow(0);
    			
    			//Commits the changes to the DataStore.
                datastore.Update();
    
                /* The following SQL is generated:
                exec dbo.DeletePerson @PersonID=1
                
                */
            }
        }
    }
    

    Example Refer To

    DataWindow File: d_person_with_deleteaction

    Back to top Generated by Appeon