Show / Hide Table of Contents

    DwTemplateAttribute Class

    .NET Standard 2.x

    Specifies the template for importing and exporting data, corresponding to the template defined by DataWindow.

    Namespace: DWNet.Data

    Assembly: DWNet.Data.dll

    Inheritance Constructor

    System.Attribute

    Syntax

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

    Constructors

    Name Description
    DwTemplateAttribute(DataFormat format, string name, string path) Initializes a new instance of the DwTemplateAttribute class.

    Properties

    Name Return Type Description
    Format DataFormat The template format.
    Name string The template name.
    Path string The template location.
    IsDefault bool The default template.

    Remarks

    The DataWindow template must be converted before it can be used by C# DataStore. The DataWindow template will be automatically exported and converted when DataWindows are converted to models.

    Examples

    The following code example demonstrates how to use the Model DwTemplate attribute. The example uses the XML template defined in DwTemplate to export data from DataStore.

    Model: D_Department_With_Xmltemplate
    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_department_with_xmltemplate", DwStyle.Grid)]
        [Table("Department")]
        #region DwSelectAttribute  
        [DwSelect("PBSELECT( VERSION(400) TABLE(NAME=\"Department\" ) @(_COLUMNS_PLACEHOLDER_) )")]
        #endregion
        [DwSort("departmentid A")]
        [DwKeyModificationStrategy(UpdateSqlStrategy.DeleteThenInsert)]
        [UpdateWhereStrategy(UpdateWhereStrategy.KeyAndConcurrencyCheckColumns)]
        [DwTemplate(DataFormat.Xml, "xml_defalut", "Templates\\d_department_with_xmltemplate.tpl.xml_defalut.xml", IsDefault = true)]
        public class D_Department_With_Xmltemplate
        {
            [Key]
            [DwColumn("Department", "DepartmentID")]
            public int Departmentid { get; set; }
    
            [ConcurrencyCheck]
            [StringLength(50)]
            [DwColumn("Department", "Name")]
            public string Name { get; set; }
    
            [ConcurrencyCheck]
            [DwColumn("Department", "Budget")]
            public decimal Budget { get; set; }
    
            [ConcurrencyCheck]
            [DwColumn("Department", "StartDate")]
            public DateTime Startdate { get; set; }
    
            [ConcurrencyCheck]
            [DwColumn("Department", "Administrator")]
            public int? Administrator { get; set; }
    
        }
    
    }
    
    Example Method:
    using System;
    using DWNet.Data;
    
    namespace Appeon.ApiDoc.DwTemplateAttributeExamples
    {
        public class DwTemplateAttributeExample
        {
            private readonly SchoolContext _context;
    
            public DwTemplateAttributeExample(SchoolContext dataContext)
            {
                // Sets the data context.
                _context = dataContext;
            }
    
            public void Example()
            {
                var datastore = new DataStore("d_department_with_xmltemplate", _context);
                datastore.Retrieve();
    
                //Gets the XML template.
                var template = datastore.GetTemplate("xml_defalut");
                //Exports data from DataStore by using the template.
                var xml = DwTemplateExporter.Export(datastore, template);
    
                // Shows the content of XML.
                Console.WriteLine($"{xml}");
    
                /* This code example produces the following output:
                
                <?xml version="1.0" encoding="UTF-16LE" standalone="no"?>
                <d_department_with_xmltemplate>
      
                  <d_department_with_xmltemplate_row>
                    <departmentid>1</departmentid>
                    <name>Engineering</name>
                    <budget>350000.0000</budget>
                    <startdate>2007-09-01T00:00:00</startdate>
                    <administrator>2</administrator>
                  </d_department_with_xmltemplate_row>
      
                  <d_department_with_xmltemplate_row>
                    <departmentid>2</departmentid>
                    <name>English</name>
                    <budget>120000.0000</budget>
                    <startdate>2007-09-01T00:00:00</startdate>
                    <administrator>6</administrator>
                  </d_department_with_xmltemplate_row>
      
                  <d_department_with_xmltemplate_row>
                    <departmentid>4</departmentid>
                    <name>Economics</name>
                    <budget>200000.0000</budget>
                    <startdate>2007-09-01T00:00:00</startdate>
                    <administrator>4</administrator>
                  </d_department_with_xmltemplate_row>
      
                  <d_department_with_xmltemplate_row>
                    <departmentid>7</departmentid>
                    <name>Mathematics</name>
                    <budget>250000.0000</budget>
                    <startdate>2007-09-01T00:00:00</startdate>
                    <administrator>3</administrator>
                  </d_department_with_xmltemplate_row>
      
                  <d_department_with_xmltemplate_row>
                    <departmentid>10</departmentid>
                    <name>department name</name>
                    <budget>20.0000</budget>
                    <startdate>2020-04-02T10:46:03</startdate>
                    <administrator>2</administrator>
                  </d_department_with_xmltemplate_row>
      
                </d_department_with_xmltemplate>
                */
            }
        }
    }
    

    Example Refer To

    DataWindow File: d_department_with_xmltemplate

    Back to top Generated by Appeon