I'm having a problem using Silverlight 5, Ria and Entity Framework.
When saving a modified entity, the SubmitChanges() call returns with some of the entity's navigation properties set to null. The save occurred properly; the correct values are saved, and if the entity is recalled later the values are read in correctly, the navigation properties set with the proper values.
But the client's context is getting updated with null values and the screen validation is kicking in.
change set immediately before Save:
change set immediately after Save:
Anyone know why this is happening?
I have tried refreshing the data after saving; by calling the same query used to fill the screen, with LoadBehavior.RefreshCurrent. The data is being recalled by it's parent, so when it gets refreshed all the child entities now have their navigation properties set to null. Not just the modified entities.
public kcc_Incentive GetKcc_IncentiveByID(Guid IncentiveID)
{
//kcc_Incentive Incentive = this.ObjectContext.kcc_Incentive.Where(i => i.IncentiveId == IncentiveID).FirstOrDefault();
//if (Incentive != null)
//{
// Incentive.kcc_IncentiveProductType.Load(); //these are the entities I'm having trouble with
// foreach (kcc_IncentiveProductType t in Incentive.kcc_IncentiveProductType)
// {
// t.rate_FullModelReference.Load();
// t.rate_BaseModelReference.Load();
// t.rate_SeriesReference.Load();
// }
//}
//return Incentive;
//getting same results regardless of how it is loaded
return ObjectContext.kcc_Incentive
.Include("kcc_IncentiveProductType.rate_FullModel")
.Include("kcc_IncentiveProductType.rate_BaseModel")
.Include("kcc_IncentiveProductType.rate_Series")
.Include("kcc_IncentiveProductType.rate_ProductType.dms_Make")
.FirstOrDefault(i => i.IncentiveId == IncentiveID);
}
Can anyone help me keep my values after they have been saved?
I found the problem, its was very specific to how my logic here was working. It turned out to be some cascading logic that set my ids to null. Here is what I have learned, in case someone (or myself in the future) has a similar problem.
If you have extra client-side properties in your entity, these properties will be cleared during the SubmitChanges call. The server does not know about them and they become set to the default value for that type.
If you happen to have logic for when those client-side properties change, that logic will run during the save as the values get cleared by the server. In my case I needed to suppress the property changed logic until after the save, then reset the client side properties.