Silverlight WCF RIA从单个项目加载

时间:2011-07-15 15:41:11

标签: c# silverlight wcf-ria-services

您好我对如何从单个项目中的表格而不是集合中获得单个“项目”感到困惑...

这是我的viewmodel:

public class ProjectViewModel : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged = delegate { };

    private int _loadedProjectId;
    public int LoadedProjectId
    {
        get
        {
            return _loadedProjectId;
        }
        set
        {
            if (value != _loadedProjectId)
            {
                _loadedProjectId = value;
                _Context.Load(_Context.GetProjectFromIdQuery(_loadedProjectId)); 
                PropertyChanged(this, new PropertyChangedEventArgs("LoadedProjectId"));
            }
        }
    }

    public Project loadedProject { get; set; }
    public IEnumerable<Project> Projects { get; set; }

    private myDomainContext _Context = new myDomainContext();

    public ProjectViewModel()
    {

        Projects = _Context.Projects;
        if (!DesignerProperties.IsInDesignTool)
        {
            _Context.Load(_Context.GetProjectsQuery());
        }

    }
}

问题出在这里

_Context.Load(_Context.GetProjectFromIdQuery(_loadedProjectId)); 

因为我不想在我的上下文中加载它但我想做这样的事情:(但显然我不能)

loadedProject = _Context.GetProjectFromIdQuery(_loadedProjectId);

以下是我的域名服务中的查询:

    public IQueryable<Project> GetProjects()
    {
        return this.ObjectContext.Projects;
    }

    public Project GetProjectFromId(int id)
    {
        return this.ObjectContext.Projects.SingleOrDefault(t => t.Id == id);
    }

我这样做是错误的吗?我应该只搜索我已经拥有的项目集合中的项目吗?

tx揭示了这一点!

1 个答案:

答案 0 :(得分:5)