在 WCF RIA 服务中使用实体作为调用方法的参数的替代方法
你好,你会的!关于 StackOverflow 的第一个问题! :-)
场景如下:我们正在使用 Silverlight 4 开发一个 Web 应用程序,并使用 WCF RIA Services 1.0 SP1 Beta 来提供 Web 服务。我的实体位于实体框架设计器中,但我使用稍作修改的 ADO.NET C# POCO 实体生成器模板来生成类。
我想做的是在域服务中有一个具有以下签名的方法:
[EnableClientAccess]
public class ResultService : DomainService
{
[Invoke]
public SerializableResult CalculateResult(EntityOne e1, EntityTwo e2);
}
我通过其他服务中的查询将 EntityOne 和 EntityTwo 返回给客户端,如下所示:
[EnableClientAccess]
public class EntityOneService : DomainService
{
public IQueryable<EntityOne> GetEntityOnes();
}
[EnableClientAccess]
public class EntityOneService : DomainService
{
public IQueryable<EntityTwo> GetEntityTwos();
}
这些类成功在 Silverlight 项目中生成。 SerializedResult没有有键。
当我尝试编译时,出现以下错误:“名为“CalculateResult”的操作不符合所需的签名。参数类型必须是实体或复杂类型、复杂类型的集合或预定义的可序列化类型之一。 ”
在我的研究中,我发现最有用的信息是 Jeff 的这篇文章的评论汉德利。
值得注意的是,彼得在评论中问道:
如果我的复杂对象具有 [Key] 属性,我会收到“不符合所需签名...”编译错误。当我删除此属性时,我可以使用该对象作为调用操作的参数。
杰夫的回应:
这是设计使然。复杂对象不能具有 Key 属性。如果您有一个键,则该类将被视为实体。
因此,听起来似乎任何进一步的努力试图让我的方法发挥作用都是徒劳的。但是,我想知道其他人是否遇到过这个问题,以及他们是如何解决的。
非常感谢!
Howdy, ya'll! First question on StackOverflow! :-)
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.
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);
}
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();
}
Those classes are successfully being generated in the Silverlight project. The SerializableResult does not have a key.
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."
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:
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's response:
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.
Thanks very much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我有以下内容,它对我有用。
I have the following and it works for me.
非常感谢 Jeff Handley 先生和 Dinesh Kulkarni 先生的回答(通过 Twitter )。
为了将实体用作调用方法中的参数,必须通过同一 DomainService 中存在的查询方法公开该实体。这一限制的目的是
通过添加两个虚拟查询方法(请参阅 Jeff 的答案作为示例),我能够编译我的代码。
Many thanks to Mr. Jeff Handley and Mr. Dinesh Kulkarni for the answer (through Twitter).
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
By adding two dummy Query methods (see Jeff's answer for an example), I was able to compile my code.