{{indexmenu_n>30}}
===== DB Adapter - MappingFunktionen (ExecScalar) =====
Für die Umsetzung von Mappingfunktionen erbt man am besten von der Klasse eBiss.DbAdapter.Functions und kann dann folgende Methoden verwenden:
* object ExecScalar(table, column, where-condition),
* object ExecuteSqlScalar(sql statement) oder
* object[] ExecuteSqlScalarMultiColumns(sql statement).
Beispiele:
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()}.");
}
}