context: // ReSharper disable All
  using System.Collections.Generic;
  using System.Data;
  using System.Dynamic;
  using System.Linq;
  using MixERP.Net.DbFactory;
  using MixERP.Net.EntityParser;
  using MixERP.Net.Framework;
  using MixERP.Net.Framework.Extensions;
  using Npgsql;
  using PetaPoco;
  using Serilog;
  
  namespace MixERP.Net.Schemas.Core.Data
  {
      /// <summary>
      /// Provides simplified data access features to perform SCRUD operation on the database table "core.tax_rate_types".
      /// </summary>
      public class TaxRateType : DbAccess, ITaxRateTypeRepository
      {
          /// <summary>
          /// The schema of this table. Returns literal "core".
          /// </summary>
          public override string _ObjectNamespace => "core";
  
          /// <summary>
          /// The schema unqualified name of this table. Returns literal "tax_rate_types".
          /// </summary>
          public override string _ObjectName => "tax_rate_types";
  
          /// <summary>
          /// Login id of application user accessing this table.
          /// </summary>
          public long _LoginId { get; set; }
  
          /// <summary>
          /// User id of application user accessing this table.
          /// </summary>
          public int _UserId { get; set; }
  
          /// <summary>
          /// The name of the database on which queries are being executed to.
          /// </summary>
          public string _Catalog { get; set; }
  
          /// <summary>
          /// Performs SQL count on the table "core.tax_rate_types".
          /// </summary>
          /// <returns>Returns the number of rows of the table "core.tax_rate_types".</returns>
          /// <exception cref="UnauthorizedException">Thown when the application user does not have sufficient privilege to perform this action.</exception>
          public long Count()
          {
              if (string.IsNullOrWhiteSpace(this._Catalog))
              {
                  return 0;
              }
  
              if (!this.SkipValidation)
              {
                  if (!this.Validated)
                  {
                      this.Validate(AccessTypeEnum.Read, this._LoginId, this._Catalog, false);
                  }
                  if (!this.HasAccess)
                  {
                      Log.Information("Access to count entity \"TaxRateType\" was denied to the user with Login ID {LoginId}", this._LoginId);
                      throw new UnauthorizedException("Access is denied.");
                  }
              }
  
              const string sql = "SELECT COUNT(*) FROM core.tax_rate_types;";
              return Factory.Scalar<long>(this._Catalog, sql);
          }
  
          /// <summary>
          /// Executes a select query on the table "core.tax_rate_types" to return all instances of the "TaxRateType" class. 
          /// </summary>
          /// <returns>Returns a non-live, non-mapped instances of "TaxRateType" class.</returns>
          /// <exception cref="UnauthorizedException">Thown when the application user does not have sufficient privilege to perform this action.</exception>
          public IEnumerable<MixERP.Net.Entities.Core.TaxRateType> GetAll()
          {
              if (string.IsNullOrWhiteSpace(this._Catalog))
              {
                  return null;
              }
  
              if (!this.SkipValidation)
              {
                  if (!this.Validated)
                  {
                      this.Validate(AccessTypeEnum.ExportData, this._LoginId, this._Catalog, false);
                  }
                  if (!this.HasAccess)
                  {
                      Log.Information("Access to the export entity \"TaxRateType\" was denied to the user with Login ID {LoginId}", this._LoginId);
                      throw new UnauthorizedException("Access is denied.");
                  }
              }
  
              const string sql = "SELECT * FROM core.tax_rate_types ORDER BY tax_rate_type_code;";
              return Factory.Get<MixERP.Net.Entities.Core.TaxRateType>(this._Catalog, sql);
          }
  
          /// <summary>
          /// Executes a select query on the table "core.tax_rate_types" to return all instances of the "TaxRateType" class to export. 
          /// </summary>
          /// <returns>Returns a non-live, non-mapped instances of "TaxRateType" class.</returns>
          /// <exception cref="UnauthorizedException">Thown when the application user does not have sufficient privilege to perform this action.</exception>
          public IEnumerable<dynamic> Export()
          {
              if (string.IsNullOrWhiteSpace(this._Catalog))
              {
                  return null;
              }
  
              if (!this.SkipValidation)
              {
                  if (!this.Validated)
                  {
                      this.Validate(AccessTypeEnum.ExportData, this._LoginId, this._Catalog, false);
                  }
                  if (!this.HasAccess)
                  {
                      Log.Information("Access to the export entity \"TaxRateType\" was denied to the user with Login ID {LoginId}", this._LoginId);
                      throw new UnauthorizedException("Access is denied.");
                  }
              }
  
              const string sql = "SELECT * FROM core.tax_rate_types ORDER BY tax_rate_type_code;";
              return Factory.Get<dynamic>(this._Catalog, sql);
          }
  
          /// <summary>
          /// Executes a select query on the table "core.tax_rate_types" with a where filter on the column "tax_rate_type_code" to return a single instance of the "TaxRateType" class. 
          /// </summary>
          /// <param name="taxRateTypeCode">The column "tax_rate_type_code" parameter used on where filter.</param>
          /// <returns>Returns a non-live, non-mapped instance of "TaxRateType" class mapped to the database row.</returns>
          /// <exception cref="UnauthorizedException">Thown when the application user does not have sufficient privilege to perform this action.</exception>
          public MixERP.Net.Entities.Core.TaxRateType Get(string taxRateTypeCode)
          {
              if (string.IsNullOrWhiteSpace(this._Catalog))
              {
                  return null;
              }
  
              if (!this.SkipValidation)
              {
                  if (!this.Validated)
                  {
                      this.Validate(AccessTypeEnum.Read, this._LoginId, this._Catalog, false);
                  }
                  if (!this.HasAccess)
                  {
                      Log.Information("Access to the get entity \"TaxRateType\" filtered by \"TaxRateTypeCode\" with value {TaxRateTypeCode} was denied to the user with Login ID {_LoginId}", taxRateTypeCode, this._LoginId);
                      throw new UnauthorizedException("Access is denied.");
                  }
              }
  
              const string sql = "SELECT * FROM core.tax_rate_types WHERE tax_rate_type_code=@0;";
              return Factory.Get<MixERP.Net.Entities.Core.TaxRateType>(this._Catalog, sql, taxRateTypeCode).FirstOrDefault();
          }
  
          /// <summary>
          /// Executes a select query on the table "core.tax_rate_types" with a where filter on the column "tax_rate_type_code" to return a multiple instances of the "TaxRateType" class. 
          /// </summary>
          /// <param name="taxRateTypeCodes">Array of column "tax_rate_type_code" parameter used on where filter.</param>
          /// <returns>Returns a non-live, non-mapped collection of "TaxRateType" class mapped to the database row.</returns>
          /// <exception cref="UnauthorizedException">Thown when the application user does not have sufficient privilege to perform this action.</exception>
          public IEnumerable<MixERP.Net.Entities.Core.TaxRateType> Get(string[] taxRateTypeCodes)
          {
              if (string.IsNullOrWhiteSpace(this._Catalog))
              {
                  return null;
              }
  
              if (!this.SkipValidation)
              {
                  if (!this.Validated)
                  {
                      this.Validate(AccessTypeEnum.Read, this._LoginId, this._Catalog, false);
                  }
                  if (!this.HasAccess)
                  {
                      Log.Information("Access to entity \"TaxRateType\" was denied to the user with Login ID {LoginId}. taxRateTypeCodes: {taxRateTypeCodes}.", this._LoginId, taxRateTypeCodes);
                      throw new UnauthorizedException("Access is denied.");
                  }
              }
  
              const string sql = "SELECT * FROM core.tax_rate_types WHERE tax_rate_type_code IN (@0);";
  
              return Factory.Get<MixERP.Net.Entities.Core.TaxRateType>(this._Catalog, sql, taxRateTypeCodes);
          }
  
          /// <summary>
          /// Custom fields are user defined form elements for core.tax_rate_types.
          /// </summary>
          /// <returns>Returns an enumerable custom field collection for the table core.tax_rate_types</returns>
          /// <exception cref="UnauthorizedException">Thown when the application user does not have sufficient privilege to perform this action.</exception>
          public IEnumerable<PetaPoco.CustomField> GetCustomFields(string resourceId)
          {
              if (string.IsNullOrWhiteSpace(this._Catalog))
              {
                  return null;
              }
  
              if (!this.SkipValidation)
              {
                  if (!this.Validated)
                  {
                      this.Validate(AccessTypeEnum.Read, this._LoginId, this._Catalog, false);
                  }
                  if (!this.HasAccess)
                  {
                      Log.Information("Access to get custom fields for entity \"TaxRateType\" was denied to the user with Login ID {LoginId}", this._LoginId);
                      throw new UnauthorizedException("Access is denied.");
                  }
              }
  
              string sql;
              if (string.IsNullOrWhiteSpace(resourceId))
              {
                  sql = "SELECT * FROM core.custom_field_definition_view WHERE table_name='core.tax_rate_types' ORDER BY field_order;";
                  return Factory.Get<PetaPoco.CustomField>(this._Catalog, sql);
              }
  
              sql = "SELECT * from core.get_custom_field_definition('core.tax_rate_types'::text, @0::text) ORDER BY field_order;";
              return Factory.Get<PetaPoco.CustomField>(this._Catalog, sql, resourceId);
          }
  
          /// <summary>
          /// Displayfields provide a minimal name/value context for data binding the row collection of core.tax_rate_types.
          /// </summary>
          /// <returns>Returns an enumerable name and value collection for the table core.tax_rate_types</returns>
          /// <exception cref="UnauthorizedException">Thown when the application user does not have sufficient privilege to perform this action.</exception>
          public IEnumerable<DisplayField> GetDisplayFields()
          {
  
gt:             List<DisplayField> displayFields = new List<DisplayField>();