开发者

Entity Framework Foreign Key Table isn't saving changes made to its BindingSource

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:

Entity Framework Foreign Key Table isn't saving changes made to its BindingSource

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();
bsVehicleOpt开发者_开发技巧ions.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?).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜