eBiss 3

Hilfe & Dokumentation

User Tools

Site Tools


Sidebar

en:howtos:dbadapter:execscalar

DB Adapter - mapping functions (ExecScalar)

For creating a mapping function that executes a DB operation inherit from eBiss.DbAdapter.Functions and use one of the following methods:

  • object ExecScalar(table, column, where-condition),
  • object ExecuteSqlScalar(sql statement) or
  • object[] ExecuteSqlScalarMultiColumns(sql statement).

Examples:

public class Functions: eBiss.DbAdapter.Functions
{
   [MappingFunction]
   public void CheckEanExists(string ean)
   {
       Log.Info("Check EAN {0} exists", ean);
 
       object o = base.ExecScalar("ArticleDetail", "Id", string.Format(" Ean = '{0}' ", ean));
 
       if ( o == null )
          throw new ApplicationException("EAN " + ean + " is not in DB - PRICAT-Pool");
 
   }
}
public class Functions: eBiss.DbAdapter.Functions
{
   [MappingFunction]
   public void CheckEanExists(string ean)
   {
       Log.Info("Check EAN {0} exists", ean);
 
       object o = base.ExecuteSqlScalar(string.Format("SELECT Id FROM ArticleDetail WHERE Ean = '{0}' ", ean));
 
       if ( o == null )
          throw new ApplicationException("EAN " + ean + " is not in DB - PRICAT-Pool");
 
   }
}
public class Functions: eBiss.DbAdapter.Functions
{
   [MappingFunction]
   public void CheckEanSize(string ean, string size)
   {
       Log.Info("Check EAN {0} is of size {1}", ean, size);
 
       object[] o = base.ExecuteSqlScalarMultiColumns(string.Format("SELECT  ArticleNumber, Color, Size FROM ArticleDetail Ean = '{0}' ", ean));
 
       if ( o == null && o.Length == 0)
          throw new ApplicationException("EAN " + ean + " is not in DB - PRICAT-Pool");
       else if (o[2].ToString() != size)
          throw new ApplicationException($"EAN {ean} has not the expected size of {size}, is defined as ArticleNumber: {o[0].ToString()} Color: {o[1].ToString()}, Size: {o[2].ToString()}.");
 
   }
}
en/howtos/dbadapter/execscalar.txt · Last modified: 2024/02/20 08:15 by 127.0.0.1