2016-05-30 77 views
0

我在使用Silverlight 5,Ria和实体框架时遇到问题。实体ria在保存后删除导航属性值

保存修改后的实体时,SubmitChanges()调用返回,其中一些实体的导航属性设置为null。保存正确发生;正确的值将被保存,如果稍后调用实体,则会正确读取值,导航属性将使用适当的值进行设置。

但客户端的背景是越来越空值和屏幕验证蹬更新

变化立即设置保存之前: change set before save

改变保存后立即设置: Change set after save

任何人都知道为什么会发生这种情况?

我试过刷新数据后保存;通过调用与LoadBehavior.RefreshCurrent相同的查询来填充屏幕。数据正在被其父母调用,因此当它被刷新时所有子实体现在都将其导航属性设置为空。不只是修改的实体。

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); 
} 

任何人都可以帮我保存我的价值后,他们已被保存?

回答

0

我发现问题,它是非常具体的如何我的逻辑在这里工作。事实证明,这是一些级联逻辑,将我的id设置为null。以下是我所学到的,以防某人(或我未来)有类似的问题。

如果您的实体中有额外的客户端属性,这些属性将在SubmitChanges调用期间被清除。服务器不知道它们,并将它们设置为该类型的默认值。

如果你碰巧有逻辑,当这些客户端属性改变时,逻辑将在保存期间运行,因为服务器清除值。在我的情况下,我需要压缩属性更改逻辑,直到保存后,然后重置客户端属性。