I found something weird. Let's say I have a Car model and a Company model.
So my Car model has a CompanyId row.
Let's say I change a Car's CompanyId then I SubmitChanges on the DataContext.
Here's my problem: The CompanyId of my Car model gets updated. But the Car.Company relation does NOT.
So if I change Car.CompanyId from 1 to 2. Then I output Car.Company.CompanyId, it'll show up 1 instead of 2.
So my question is: Is there a way to update EVERYTHING in the DataContext?
I'm currently using:
public void RefreshCollection()
{
// On rafraichit les données à partir de la DB.
dataContext.Refresh(RefreshMode.KeepChanges);
// On va chercher les données complête de la table.
purchaseOrders = from po in dataContext.PurchaseOrders
orderby po.PurchaseOrderId ascending
select po;
}
To update my collection.
And:
private void sauvegarderToolStripMenuItem_Click(object sender, EventArgs e)
{
purchaseOrder.OrderDate = orderDate.Value;
purchaseOrder.RequiredDate = requiredDate.Value;
purchaseOrder.ShipTo = shipTo.Text;
purchaseOrder.State = helper.ConvertComboBoxIndexToStateIndex(
stateKey.SelectedIndex);
// On cast un autre type pour le forcer à être un ComboBoxItem
var supplierItem = (ComboBoxItem)supplierId.SelectedItem;
purchaseOrder.SupplierId = supplierItem.Id;
dataContext.SubmitChanges();
}
To submit my changes.