Save Changes to Linq-to-SQL

So, here is my, hopefully, unique back of this common problem.

I make my request, get my objects, then pass the object to the form, where it fills the form with data from the object (this is not passed by reference).

Then I edit the values ​​of the object that was requested (via the form), and then returns a new object built from the values ​​in the form.

Then I want to update this in the database. Attach does nothing (running, but not updating). SubmitChanges also does nothing (and both do nothing when shared).

What am I missing?

Update: here is the code I'm using:

// In constructor
_dataMap = new DataMapDataContext();
_addresses = _dataMap.AddressItems
         .Where(address => address.InsertUserName == _currentUser.Name).ToList();



public void EditButtonClick()
{
    using (AddAddressForm form = new AddAddressForm(_addresses[_currentAddress]))
    {
        form.Text = "Edit Address";
        if (DialogResult.OK == form.ShowDialog())
        {
            _addresses[_currentAddress] = form.Item;
            _dataMap.SubmitChanges();
            DisplayItem();
        }
    }
}
+2
source share
2 answers

, SubmitChanges()

using(MyDataContext db = new MyDataContext())
{
    // get the record
    Product dbProduct = db.Products.Single(p => p.ID == 1);

    // set new values
    dbProduct.Quantity = 5; 
    dbProduct.IsAvailable = false;

    // save them back to the database
    db.SubmitChanges();
}
+6

, .

, . , , , , ( Linq-to-SQL .)

:

AddressItem itemToEdit = _addresses[_currentAddress];
using (AddAddressForm form = new AddAddressForm(ref itemToEdit))
-4

All Articles