I came across an example of the implementation an an interface. Portion of code is
public partial interface IDataProvider
{
DataTable GetEmployeeAbsenceDurationTypes();
void AlterEmployeeAbsenceDurationTypes(DataTable lookUpTable);
}
public partial class DataProvider : IDataProvider
{
public DataTable GetEmployeeAbsenceDurationTypes()
{
return GetEmployeeAbsenceDurationTypes((DbTransaction)null);
}
public DataTable GetEmployeeAbsenceDurationTypes(DbTransaction tran)
{
//Db Operations
}
}
My first question is about this "DbTransaction" class. Its not in my project, is it a build in class?
My second question is, why in the DataProvider (the implementing class), the function is calling another overload of itself?
DbTransaction
is a common base-class for representing database transactions in ADO.NET; each actual ADO.NET provider subclasses this (typically) - for example SqlTransaction : DbTransaction
(the sql-server client).
Calling an overload of self is a common way of implementing optional parameters, without code duplication prior to their addition in C# 4.0. In this case, that is essentially a pre-4.0 way of implementing:
public DataTable GetEmployeeAbsenceDurationTypes(DbTransaction tran = null) {...}
either implementation (overloads or optional parameter) allows usage of the form:
obj.GetEmployeeAbsenceDurationTypes(); // without transaction
obj.GetEmployeeAbsenceDurationTypes(tran); // with transaction
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With