3
很長一段時間我一直在做以下操作:哪一個最好在數據庫中插入一行?
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();
}
哪種方法被認爲是最好的做法,爲什麼?
我已經使用了這兩種風格,並沒有區別,你可以採取任何他們 – Zia