Ste*_*e L 2 sql linq linq-to-sql
// goal: update Address record identified by "id", with new data in "colVal"
string cstr = ConnectionApi.GetSqlConnectionString("SwDb"); // get connection str
using (DataContext db = new DataContext(cstr)) {
Address addr = (from a in db.GetTable<Address>()
where a.Id == id
select a).Single<Address>();
addr.AddressLine1 = colValue.Trim();
db.SubmitChanges(); // this seems to have no effect!!!
}
Run Code Online (Sandbox Code Playgroud)
在调试器中,addr具有db表中的所有当前值,并且我可以在调用db.SubmitChanges()之前验证AddressLine1是否已更改... SQL Profiler在SubmitChanges行执行时仅显示"重置连接".任何人都知道为什么这不起作用?谢谢!