使用存储过程从EF4返回嵌套复杂类型

时间:2010-09-23 15:57:29

标签: silverlight entity-framework silverlight-4.0 entity-framework-4 wcf-ria-services

是否可以使用EF从多个不同的存储过程返回嵌套复杂类型? (例如ClientSelect,ClientAddressSelect)

我导入了一些存储过程并添加了函数导入,并为每种返回类型创建了一个Complex Type。 (例如Client和ClientAddress)。

现在,例如,我想将ClientAddress Complex Type添加到Client复杂类型。我将使用ClientSelect返回Client的所有值,然后使用ClientAddressSelect填充ClientAddress。

当我尝试运行ClientSelect时,出现以下错误:

"Nested ComplexType property 'ClientAddresses' in the ReturnType 'Client' of the function 'myModel.ClientSelect' is not supported, please consider flattening the nested ComplexType property."

这使得它看起来不可能,还有另一种方法吗?我正在使用WCF RIA服务,并希望在将其发送到Silverlight客户端之前填充服务器端的完整Client对象。

任何帮助/建议表示赞赏。

2 个答案:

答案 0 :(得分:0)

最新的RIA Services SP1(刚刚作为BETA发布)现在支持复杂类型。你可能想要考虑它,因为我们发现它也解决了RIA服务的许多问题。

适用于Silverlight 4的WCF RIA Services V1.0 SP1 Beta: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=330f6831-5b90-4315-b042-96127a4a7efc

WCF RIA服务工具包2010年10月: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=a23325ef-7b1f-4c92-9fd5-ffee48f7c7bc

答案 1 :(得分:0)

我通过将复杂类型声明添加到局部类并使用[Include]和[Associate]属性来解决此问题。

using System.ServiceModel.DomainServices.Server;
using System.ComponentModel.DataAnnotations;

public partial class Client
{
  [Include]
  [Association("Client_Address", "ClientAddressID", "ClientAddressID")]
  public IEnumerable<ClientAddress> Addresses { get; set; }
}

然后我调用SP来填充Client,然后调用一个单独的存储过程来填充Client.Addresses