2009-11-12 65 views
2

我正在阅读并在RIA上做一些RnD作为新的Silverlight项目的解决方案。检索单个实体+ Ria服务

我已经阅读了很多文档,并决定使用.Net RIA Services做一个小型的系统模型。

我想知道如何从域服务中获得单个实体?

例如: 我想一个人并填充表格:

public Person GetSinglePerson() 
     { 
      return new Person { ID = 4, FirstName = "Cyanide", LastName = "Happiness", Status=3 }; 

} 说我使用的DomainDataSource:

<riaControls:DomainDataSource x:Name="source2" QueryName="GetSinglePersonQuery" AutoLoad="True"> 
        <riaControls:DomainDataSource.DomainContext> 
         <web:DataContext/> 
        </riaControls:DomainDataSource.DomainContext> 
       </riaControls:DomainDataSource> 

这只返回EntityCollectionView?例如,如何将表单绑定到Person类中的属性?

像:

<TextBox Text="{Binding FirstName, ElementName=source2}"/> 

一切似乎又回来了为IEnumerable或CollectionViews(如数据样本中结合),这是不是一个单一的实体有用。

我想单人入口,为什么我要一个CollectionView,我无法直接访问属性。

我也使用:

LoadOperation<Person> oLoadOperation = oDataContext.Load(oDataContext.GetSinglePersonQuery()); 

我非常接近这个RIA想法放弃,只是一个正常的WCF服务去,因为它是更可预测和可管理性在这个阶段。

回答

-1

我认为你有你的课用[EnableClientAccess]装饰?

尝试

<TextBlock Text="{Binding Path=Person.FirstName}" 
3
ctxt.Load(ctxt.GetEmployeeByNumberQuery("ABC123")).Completed += new System.EventHandler(EmployeeLoad_Completed); 


void EmployeeLoad_Completed(object sender, System.EventArgs e) 
{ 
    Employee myEmployee = (sender as LoadOperation<Employee>).Entities.FirstOrDefault(); 
} 
1
 HumanResourceContext context = new HumanResourceContext(); 

     var addressquery = context.GetAddressesQuery(); 
     addressquery = addressquery.Where(a => a.AddressId == 1); 

     context.Load(addressquery, (op) => 
      { 
       Address address = op.Entities.FirstOrDefault(); 

       MessageBox.Show(address.Street1); 
      }, null);