Note that there are some explanatory texts on larger screens.

plurals
  1. POEntity Framework Foreign Key Table isn't saving changes made to its BindingSource
    primarykey
    data
    text
    <p>I have two tables:</p> <pre><code>CREATE TABLE `Vehicles` ( `ID` int(10) unsigned NOT NULL AUTO_INCREMENT, ... Other columns PRIMARY KEY (`ID`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1 </code></pre> <p>And:</p> <pre><code>CREATE TABLE `VehicleOptions` ( `ID` int(10) unsigned NOT NULL AUTO_INCREMENT, `VehicleID` int(10) unsigned NOT NULL, ... Other columns PRIMARY KEY (`ID`), KEY `FK_Vehicles_to_VehicleOptions` (`VehicleID`), CONSTRAINT `FK_Vehicles_to_VehicleOptions` FOREIGN KEY (`VehicleID`) REFERENCES `vehicles` (`ID`) ON DELETE CASCADE ON UPDATE NO ACTION ) ENGINE=InnoDB DEFAULT CHARSET=latin1 </code></pre> <p>Here is a picture of the Data Objects:</p> <p><img src="https://i.stack.imgur.com/MMvDt.png" alt="Data Objects"></p> <p>I drag and dropped Vehicle and VehicleOptions onto my form. I then load the databse using a LINQ query:</p> <pre><code>var dataSource = from v in Database.DataContext.Vehicles.Include("VehicleOptions") orderby v.Stock descending select v; // The vehicles BindingSource bsVehicles.DataSource = dataSource; // The vehicleoptions BindingSource bsVehicleOptions.DataSource = bsVehicles; bsVehicleOptions.DataMember = "VehicleOptions"; </code></pre> <p>Whenever I add/edit data on my form I call:</p> <pre><code>bsVehicles.SuspendBinding(); bsVehicleOptions.SuspendBinding(); Database.DataContext.SaveChanges(); bsVehicleOptions.ResumeBinding(); bsVehicles.ResumeBinding(); </code></pre> <p>The changes made to <code>bsVehicles</code> are saved in my MySQL database but the changes made to <code>bsVehicleOptions</code> are not. Even on the form, the Controls bound to <code>bsVehicleOptions</code> empty their data on <code>Database.DataContext.SaveChanges();</code> Am I missing something here?</p> <p>Note: I am using the Entity Framework V4 (I've hear the Associations in older versions were funky?).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload