在WCF RIA服务中使用实体作为调用方法的参数的替代方法 [英] Alternative to Using an Entity as a Parameter to an Invoke Method in WCF RIA Services

查看:64
本文介绍了在WCF RIA服务中使用实体作为调用方法的参数的替代方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,你会的!关于StackOverflow的第一个问题! :-)

Howdy, ya'll! First question on StackOverflow! :-)

因此,这是这种情况:我们正在使用Silverlight 4开发一个Web应用程序,并将WCF RIA Services 1.0 SP1 Beta用于该Web服务。我的实体在Entity Framework Designer中,但是我使用的是经过稍微修改的ADO.NET C#POCO实体生成器模板来生成类。

So here's the scenario: We're working on a web app with Silverlight 4 and using WCF RIA Services 1.0 SP1 Beta for the web service. I have my entities in the Entity Framework Designer, but I'm using a slightly-modified ADO.NET C# POCO Entity Generator template to generate the classes.

我要做什么d想要做的是在域服务中有一个带有以下签名的方法:

What I'd like to do is have a method inside a Domain Service with the following signature:

[EnableClientAccess]
public class ResultService : DomainService
{
    [Invoke]
    public SerializableResult CalculateResult(EntityOne e1, EntityTwo e2);
}

我正在通过其他服务中的查询将EntityOne和EntityTwo都返回给客户端,像这样:

I am returning both EntityOne and EntityTwo to the client through queries in other services, like so:

[EnableClientAccess]
public class EntityOneService : DomainService
{
    public IQueryable<EntityOne> GetEntityOnes();
}

[EnableClientAccess]
public class EntityOneService : DomainService
{
    public IQueryable<EntityTwo> GetEntityTwos();
}

这些类已成功在Silverlight中生成项目。 SerializableResult没有没有有密钥。

当我尝试编译时,出现以下错误:名为'CalculateResult'的操作没有符合所需的签名。参数类型必须是实体或复杂类型,复杂类型的集合或预定义的可序列化类型之一。

When I try to compile, I get the following error: "Operation named 'CalculateResult' does not conform to the required signature. Parameter types must be an entity or complex type, a collection of complex types, or one of the predefined serializable types."

我发现最有用的信息来自Jeff Handley撰写的这篇评论

In my research, the most helpful information I found were in the comments of this post by Jeff Handley.

值得注意的是,彼得在评论中问:

Of note, Peter asked in a comment:


我明白了如果我的复杂对象具有[Key]属性,则会出现不符合要求的签名...的编译错误。删除此属性后,可以将对象用作调用操作的参数。

I get an 'does not conform to the required signature ...' compile error if my complex object has an [Key] Attribute. When I remove this attribute I can use the object as parameter for an Invoke operation.

Jeff的响应:


这是设计使然。复杂对象不能具有Key属性。如果您有一个Key,则该类将被视为一个实体。

This is by design. Complex objects cannot have Key properties. If you have a Key the class gets treated as an Entity.

因此,听起来好像有进一步的尝试来尝试获取我的方法工作将是徒劳的。但是,我想知道是否还有其他人遇到过这个问题,以及他们如何解决这个问题。

So it sounds as if any further efforts to try to get my method to work will be futile. However, I was wondering if anyone else has come across this problem, and what they did to solve it.

非常感谢!

推荐答案

非常感谢Jeff Handley先生和Dinesh Kulkarni先生的回答(通过 Twitter )。

Many thanks to Mr. Jeff Handley and Mr. Dinesh Kulkarni for the answer (through Twitter).

为了将实体用作调用方法中的参数,实体必须通过同一DomainService中存在的查询方法公开。限制的目的是

In order for an Entity to be used as a parameter in an invoke method, that Entity must be exposed through a query method existing within the same DomainService. The intention for this restriction is that


每个域服务都必须能够独立存在。

"Each domain service needs to be able to stand on its own."

通过添加两个虚拟Query方法(请参阅Jeff的示例),我能够编译我的代码。

By adding two dummy Query methods (see Jeff's answer for an example), I was able to compile my code.

这篇关于在WCF RIA服务中使用实体作为调用方法的参数的替代方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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