DomainService 可以返回单个自定义类型吗? [英] Can a DomainService return a single custom type?

查看:22
本文介绍了DomainService 可以返回单个自定义类型吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的域服务中使用类似于以下内容的方法:

I would like a method on my in my domain service similar to:

public SystemState GetSystemStatus()
{
    return new SystemStatus
    {
        InterestingStatusValue1 = 1223,
        OtherInterstingStatusValue = "abc",
    }
}

那行不通.Silverlight 客户端应用程序不会自动生成任何内容.但是,如果我将其设为 IQueryable 方法,那么我会在客户端上生成一些内容.我将在上下文对象上获得 SystemStates 属性和 Query 方法.

That doesn't work. Nothing is auto-generated for the Silverlight client app. Howerver if I make this an IQueryable method, then I get something generated on the client. I'll get a SystemStates property and a Query method on the context object.

有没有办法让它成为一个简单的 WCF 调用?我想我可以将 WCF Silverlight Enabled 服务添加到我的 RIA 网站,然后设置一个服务参考(这不对吗?)(为什么我在 Silverlight 应用程序中看不到服务参考?)

Is there no way to make this a simple WCF call? I suppose I could a WCF Silverlight Enabled service to my RIA Web site, and then setting a Service Reference (that can't be right?) (and why can't I see the Services Reference in the Silverlight app?)

乍一看,RIA 服务似乎强制采用非常以数据为中心/简单的 CRUD,这对于表编辑器来说非常有用,但对于拖累数据网格的 LOB 应用程序而言则不然.

On first blush it seems that RIA services forces a very data-centric/easy CRUD which is great for table editors, but not so much for LOB applications that go behind drag on a datagrid and you're done.

推荐答案

您可以使用属性仅返回一个实体(假设 SystemState 是您的实体):

You can return just one entity using an attribute (assuming that SystemState is your entity):

例如:

[Query(IsComposable = false)]
public SystemState GetSystemStatus()
{
    return new SystemStatus
    {
        InterestingStatusValue1 = 1223,
        OtherInterstingStatusValue = "abc",
    }
}

请记住,这仍然是一个查询,Ria Services 将在您的 DomainContext 中生成一个方法,例如:

Remember that this is still a query and Ria Services will generate a method in your DomainContext like:

EntityQuery<SystemState> GetSystemStatusQuery()

像普通的 EntityQuery 一样使用它,但请记住,您不能对返回的对象执行查询操作(排序或过滤).

Use it like a normal EntityQuery, but keep in mind that you can't perform query operations (sorting or filtering) on the returned object.

如果要在服务器上执行操作,请尝试使用 [Invoke] 属性.例如:

If you want to execute an operation on server, try using the [Invoke] attribute. Ex:

[Invoke]
public SystemState GetSystemStatus()
{
    return new SystemStatus
    {
        InterestingStatusValue1 = 1223,
        OtherInterstingStatusValue = "abc",
    }
}

我不知道你的返回类型有多复杂,但我想如果它可以序列化,它会起作用(不确定).

I don't know how complex your return type can be, but I guess if it can be serialized, it will work (not sure).

这篇关于DomainService 可以返回单个自定义类型吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆