I just in started working an a proj that uses LINQ to SQL. I noticed the code is not using iDisposable, i myself would never pass a DataContext However since it is created in 1 method and passed to another do I need to do db.Dispose() 2 times, once per method or just once on the method that created the instance of DataContext?
protected void btnSaveCC_Click(object sender, EventArgs e)
{
var db = new DataContext();
CCBadgeInfo(db);
}
private void saveCCInfo(DataContext db)
{
var currentCase = (Case)HttpContext.Current.Items["CurrentCase"];
if (currentCase.TypeId == (int)prj.Constants.Constant..CreditFraud)
{
var applicant = db.Applicants.Where(a => a.ApplicantId == currentCase.ApplicantId).SingleOrDefault();
applicant.CCExpirationDate = tryConvertDateTime(txtCCExpirationDate.Text);
}
db.SubmitChanges();
}