简体   繁体   English

WCF RIA服务,EntitySet始终为空吗?

[英]WCF RIA Services, EntitySet always empty?

A quick question here about the new WCF Ria services beta: 关于新的WCF Ria服务beta的一个简短问题:

If I do this in code-behind: 如果我在后面的代码中这样做:

EntitySet e = MyContext.Employees EntitySet e = MyContext.Employees

It seems that the entityset is always empty at runtime? 似乎在运行时,entityset总是为空? Ie if I want to loop through the Employee entityset. 即,如果我想遍历Employee实体集。

Also, if I'm getting the Enumerator for the entityset, I'll get an error telling me that the enumerator either is empty or hasn't started yet. 另外,如果获取实体集的枚举数,则会收到一条错误消息,告诉我该枚举数为空或尚未启动。 Is there any way at all to grab a collection of entities from the context and iterate through them? 是否有任何方法可以从上下文中获取实体集合并对其进行迭代?

Thanks in advance! 提前致谢!

Have you checked within the Completed event call back? 您是否已在“ 完成的事件”回调中进行检查? Remember that within Silverlight all the calls are asynchronous. 请记住,在Silverlight中,所有调用都是异步的。 Even if you see sample code where the ItemsSource is assigned before the call back, it is relying to the fact that Employees is an ObservableCollection for the data binding. 即使您在回调之前看到在其中分配ItemsSource的示例代码,也依赖于Employees是用于数据绑定的ObservableCollection的事实。

LoadEmployeeCommand()
{
    // The Load method initiates the call to the server
    LoadOperation<Employee> loadOperation = domainContext.Load(domainContext.GetEmployeesQuery());
    // The EntitySet is still empty at this point
    employeeDataGrid.ItemsSource = domainContext.Employees; 
    loadOperation.Completed += EmployeeLoadOperationCompleted;
}

private void EmployeeLoadOperationCompleted(object sender, EventArgs e)
{
    // Don't need to reassign now but at this point the collection should be populated
    employeeDataGrid.ItemsSource = domainContext.Employees;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM