This is entity framework 4.
CurrentProperty.FMVHistories.Add(FMVPresenter.GetFMVHistoryObject());
DataLayer.AccrualTrackingEntities repository = new AccrualTrackingEntities();
repository.Properties.AddObject(CurrentProperty);
repository.Save开发者_C百科Changes();
Right before I call SaveChanges, CurrentProperty has 1 object in its FMVHistories collection, as it should. Right after the save, it has two - the second of which appears to be a copy of the first, both of which have their foreign keys set, properly.
All objects involved here are new. None were loaded in any way.
FMVHistory has a composite key of 3 fields, one of which is the foreign key to the property it's attached to.
Does anyone know why this second FMVHistory object is getting added?
It looks like this was related to how EF was handling dates. The designer of the FMVHistory table made it with a composite key, part of which was a date field. For some reason when EF put in the object, it truncated the seconds and such from the date it inserted, which broke a lot of weird stuff. I ended up killing the composite key and putting in an identity, and everything is great now.
精彩评论