Linq to Sql SubmitChanges() 関数のデバッグ機能に関して、より深い質問があります。
ローカルにキャッシュされたデータベースのテーブルにレコードを保存したい (localdbcache: サーバー SqlExpress 2008 クライアント SqlCE)。SubmitChanges を呼び出す前に、DataContext.GetChangeSet() を介して新しい項目を見つけることができます。Submit Changes を呼び出した後、挿入するアイテムは ChangeSet から削除されています。(それが、この関数が行うべきことです。) データベースのログ出力に、変更の競合やエラーはありません。例外はありません。テーブルの Count は同じ値のままです。
if ((e.Parameter == null) ||
(!e.Parameter.GetType().Equals(typeof(LibDB.Client.Vehicles))))
{
return;
}
LibDB.Client.Vehicles tmp = e.Parameter as LibDB.Client.Vehicles;
try
{
ChangeSet cs = this._dc.GetChangeSet();
if ((tmp == null) || (this._dc == null)) return;
if (this._dc.Vehicles.Where(veh => veh.Vin == tmp.Vin).Count() == 0)
this._dc.Vehicles.InsertOnSubmit(tmp);
else if (this._dc.Vehicles.Where(veh => veh.Vin == tmp.Vin).Count() == 1)
this._dc.Vehicles.Attach(tmp, true);
else
return;
using (TransactionScope ts = new TransactionScope())
{
try
{
this._dc.SubmitChanges();
//this._dc.Refresh(RefreshMode.OverwriteCurrentValues,
// this._dc.Vehicles);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
if (this._dc.Vehicles.Where(veh => veh.Vin == tmp.Vin).Count() == 1)
MessageBox.Show("Vehicle not saved.");
this.vehSelector.ResetLayout();
}
エラーを見つける希望を失っているので、助けていただければ幸いです。事前に感謝しますウィンストン