views:

77

answers:

0

I have two tables:

CREATE TABLE `Vehicles` (
    `ID` int(10) unsigned NOT NULL AUTO_INCREMENT,
    ... Other columns
    PRIMARY KEY (`ID`)
    ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1

And:

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

Here is a picture of the Data Objects:

Data Objects

I drag and dropped Vehicle and VehicleOptions onto my form. I then load the databse using a LINQ query:

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";

Whenever I add/edit data on my form I call:

bsVehicles.SuspendBinding();
bsVehicleOptions.SuspendBinding();
Database.DataContext.SaveChanges();
bsVehicleOptions.ResumeBinding();
bsVehicles.ResumeBinding();

The changes made to bsVehicles are saved in my MySQL database but the changes made to bsVehicleOptions are not. Even on the form, the Controls bound to bsVehicleOptions empty their data on Database.DataContext.SaveChanges(); Am I missing something here?

Note: I am using the Entity Framework V4 (I've hear the Associations in older versions were funky?).