如何等待进程在EntityFramework中完成?

时间:2012-09-24 23:37:49

标签: c# silverlight callback silverlight-5.0 iasyncresult

我正在与EntityFramework和Silverlight合作,我正在处理这种情况。当我尝试从EntitySet加载数据时,我必须从回调中获取数据。

现在,我需要立即获取数据,我的意思是等到流程结束。

在下一个代码中,我想要等待该过程的部分是Objectives属性。或者我不知道我是否可以将回调方法转换为IAsyncResult或类似的东西。

public class EntityService : IEntityService
{
    public EntityService()
    {
        _entities = new DatabaseDomainContext();
    }

    private DatabaseDomainContext _entities;
    public DatabaseDomainContext Entities
    {
        get { return _entities; }
        set { _entities = value; }
    }

    private EntityList<Objective> _objectives;
    public ObservableCollection<Objective> Objectives
    {
        get
        {
            if (_objectives == null)
            {
                var loadOp = _entities.Load(_entities.GetObjectivesQuery()/*, Callback, true*/);
                _objectives = new EntityList<Objective>(_entities.Objectives, loadOp.Entities);
            }

            return _objectives;
        }
    }
}

1 个答案:

答案 0 :(得分:1)

实施INotifyPropertyChanged。结果返回时,引发NotifyPropertyChanged。