【发布时间】:2018-01-16 21:09:41
【问题描述】:
当我运行以下代码时,最后一行
repository.Context.LoadProperty(userPatient.Patient.Practice, "Enterprise")
抛出异常
上下文当前没有跟踪实体
如何加载导航属性Enterprise?我不确定我错过了什么。请帮忙。
public class QuickLaunch
{
private UserPatient userPatient = null;
private PortalRepository repository = null;
public QuickLaunch(PortalRepository repository)
{
this.repository = repository;
userPatient = MySession.Current.SelectedPatient;
repository.Context.LoadProperty(userPatient.Patient.Practice, "Enterprise");
}
}
【问题讨论】:
-
repository.Context.MergeOption设置是否存在?如果是,请在使用LoadProperty之前尝试将其设置为MergeOptions.AppendOnly,或者如果不是,请尝试在您的上下文中某处找到MergeOption设置。 -
@TetsuyaYamamoto - 我尝试了你的建议,但仍然遇到同样的异常。这是我添加的。
repository.Context.MergeOption = System.Data.Services.Client.MergeOption.AppendOnly; //repository.Context.AttachTo("UserPatient", UserPatient); repository.Context.LoadProperty(userPatient.Patient.Practice, "Enterprise");
标签: asp.net-mvc asp.net-mvc-4 wcf-data-services