长期以来,我一直在做以下事情:
using(var db = new MainContext())
{
// Create license issue record
var n = new tblStoreLicenseIssue
{
Comment = comment,
EmailAddress = email,
Hash = mangled2,
LicensedTo = name,
Timestamp = unixTime,
ValidClaimID = validClaimID
};
db.tblStoreLicenseIssues.InsertOnSubmit(n);
db.SubmitChanges();
}
但我想知道这种方法是否有任何优势:
var n = new tblStoreLicenseIssue
{
Comment = comment,
EmailAddress = email,
Hash = mangled2,
LicensedTo = name,
Timestamp = unixTime,
ValidClaimID = validClaimID
};
using(var db = new MainContext())
{
db.tblStoreLicenseIssues.InsertOnSubmit(n);
db.SubmitChanges();
}
哪种方法被认为是最佳实践,为什么?