【问题标题】:Unable to load navigation property of an entity无法加载实体的导航属性
【发布时间】: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


【解决方案1】:

嗯,我确实有解决这个问题的替代方案。我可以将该特定上下文添加到会话变量中。然后,当我需要使用该上下文加载导航属性时,我总是可以使用我在会话中保存的上下文。我试过了,它有效。但我不确定这是否正确或最好的方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    相关资源
    最近更新 更多