2

にデータを追加し、ObjectSetで行いSaveChangesましたObjectContextDataGridただし、新しいデータは!に表示されません。

コード:

bsWork.DataSource = Program.EC.Addresses;
...
Address newAdr = new Address();
//change properties newAdr
...
Program.EC.Addresses.AddObject(newAdr);
Program.EC.SaveChanges(SaveOptions.AcceptAllChangesAfterSave);
データを更新したり、新しいデータを表示したりするにはどうすればよいですか?

UPD:ソリューション

...
bsWork.Add(newAdr);
Program.EC.SaveChanges(SaveOptions.AcceptAllChangesAfterSave);
...

4

1 に答える 1

1

このコードがお役に立てば幸いです。

try {
    // Try to save changes, which may cause a conflict.
    int num = context.SaveChanges();
    Console.WriteLine("No conflicts. " + num.ToString() + " updates saved.");
}
catch (OptimisticConcurrencyException) {
    // Resolve the concurrency conflict by refreshing the 
    // object context before re-saving changes. 
    context.Refresh(RefreshMode.ClientWins, orders);

// Save changes.
context.SaveChanges();
Console.WriteLine("OptimisticConcurrencyException "
    + "handled and changes saved");

}

于 2011-06-29T03:14:50.343 に答える