Initially, I had a method in our DL that would contribute to the object that it updated like this:
internal void UpdateCash(Cash Cash)
{
using (OurCustomDbConnection conn = CreateConnection("UpdateCash"))
{
conn.CommandText = @"update Cash
set captureID = @captureID,
ac_code = @acCode,
captureDate = @captureDate,
errmsg = @errorMessage,
isDebit = @isDebit,
SourceInfoID = @sourceInfoID,
PayPalTransactionInfoID = @payPalTransactionInfoID,
CreditCardTransactionInfoID = @CreditCardTransactionInfoID
where id = @cashID";
conn.AddParam("@captureID", cash.CaptureID);
conn.AddParam("@acCode", cash.ActionCode);
conn.AddParam("@captureDate", cash.CaptureDate);
conn.AddParam("@errorMessage", cash.ErrorMessage);
conn.AddParam("@isDebit", cyberCash.IsDebit);
conn.AddParam("@PayPalTransactionInfoID", cash.PayPalTransactionInfoID);
conn.AddParam("@CreditCardTransactionInfoID", cash.CreditCardTransactionInfoID);
conn.AddParam("@sourceInfoID", cash.SourceInfoID);
conn.AddParam("@cashID", cash.Id);
conn.ExecuteNonQuery();
}
}
My boss thought that creating an object every time just to update one or two fields is redundant. But I had several places in the code using this. He recommended using only UpdateCash and sending the ID for CAsh and the field I want to update. Well, the problem is that I have 2 places in the code using my original method. And these 2 places update 2 completely different fields in the Cash table. Before I could get the existing cash record and drag it into the Cash object, then update the properties that I would like to update in the database, and then send the money object back to my method above.
, . 2 , . , , 2 Cash:
internal void UpdateCash(int cashID, int paypalCaptureID)
{
using (OurCustomDbConnection conn = CreateConnection("UpdateCash"))
{
conn.CommandText = @"update Cash
set CaptureID = @paypalCaptureID
where id = @cashID";
conn.AddParam("@captureID", paypalCaptureID);
conn.ExecuteNonQuery();
}
}
internal void UpdateCash(int cashID, int PayPalTransactionInfoID)
{
using (OurCustomDbConnection conn = CreateConnection("UpdateCash"))
{
conn.CommandText = @"update Cash
set PaymentSourceID = @PayPalTransactionInfoID
where id = @cashID";
conn.AddParam("@PayPalTransactionInfoID", PayPalTransactionInfoID);
conn.ExecuteNonQuery();
}
}
, , , , , , :
UpdateCashOrderID
UpdateCashTransactionInfoID
ok, . , :
UpdateCashTransaction(int cashID, paypalTransactionID)
, , , paypalTransactionInfoID? , creditCardInfoID? ? , . , , 2 , 2 cashID:
UpdateCashTransaction(int cashID, paypalTransactionID, someOtherFieldIWantToUpdate)
. ? - ?