检索单个实体+里亚服务

发布于 2024-08-11 07:10:50 字数 1221 浏览 1 评论 0原文

我正在阅读并做一些有关 RIA 的 RnD,作为新 Silverlight 项目的解决方案。

我阅读了大量文档,并决定使用 .Net RIA 服务制作一个系统的小型模型。

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

例子: 我想找人并填写表格:

 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(如示例中的 DATA 绑定)的形式返回,这对于单个实体没有用处。

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

我还使用过:

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

我非常接近放弃这个 RIA 想法,而只是使用普通的 WCF 服务,因为它在现阶段更可预测和可管理。

I am reading and doing some RnD on RIA as a solution for a new Silverlight project.

I have read alot of the documentation and decided to do a small mockup of a system using .Net RIA Services.

I want to know how to get a Single Entity from the Domain Service?

example:
I want to get a person and populate a form:

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

}
Say I use the the DomainDataSource:

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

This only returns a EntityCollectionView? How do I bind for example in a form to properties that are in the Person Class?

Like:

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

Everything seems to come back as IEnumerable or as CollectionViews (like the DATA binding in the samples) which aren't useful for a single entity.

I want a single persons entry, why do I want a CollectionView in which I cannot access properties directly.

I have also use the:

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

I am very close to giving up on this RIA idea and just going with a normal WCF service as it is more predictable and manageable at this stage.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

千鲤 2024-08-18 07:10:50
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();
}
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();
}
十六岁半 2024-08-18 07:10:50

嘿刚刚发现这个检查一下我认为这就是你想做的

http://jeffhandley.com/archive/2009/11/10/domaindatasource-single-record.aspx

hey just found this check it out I think this is what you want to do

http://jeffhandley.com/archive/2009/11/10/domaindatasource-single-record.aspx

惟欲睡 2024-08-18 07:10:50
        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);
        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);
灼疼热情 2024-08-18 07:10:50

我想你的班级用 [EnableClientAccess] 装饰?

尝试

<TextBlock Text="{Binding Path=Person.FirstName}"

I presume you have your class decorated with [EnableClientAccess] ?

try

<TextBlock Text="{Binding Path=Person.FirstName}"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文