【发布时间】:2016-05-30 16:22:19
【问题描述】:
我在使用 Silverlight 5、Ria 和 Entity Framework 时遇到问题。
保存修改后的实体时,SubmitChanges() 调用返回时将实体的一些导航属性设置为空。保存正确发生;保存正确的值,如果稍后调用实体,则正确读取值,导航属性设置为正确的值。
但是客户端的上下文正在更新为空值,并且屏幕验证正在启动。
有人知道为什么会这样吗?
我试过保存后刷新数据;通过调用用于填充屏幕的相同查询,使用 LoadBehavior.RefreshCurrent。数据正在被其父级调用,因此当它被刷新时,所有子实体现在都将其导航属性设置为 null。不仅仅是修改后的实体。
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);
}
任何人都可以帮助我在保存我的价值观后保持这些价值观吗?
【问题讨论】:
标签: entity-framework-4 silverlight-5.0