【问题标题】:Returning nested complex types from EF4 using Stored Procedures使用存储过程从 EF4 返回嵌套的复杂类型
【发布时间】:2010-09-23 15:57:29
【问题描述】:

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

我已经导入了一些存储过程并添加了函数导入,并为每个返回类型创建了一个复杂类型。 (例如客户端和客户端地址)。

现在,例如,我想将 ClientAddress 复杂类型添加到 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 客户端之前在服务器端填充完整的客户端对象。

感谢任何帮助/建议。

【问题讨论】:

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


    【解决方案1】:

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

    适用于 Silverlight 4 的 WCF RIA 服务 V1.0 SP1 测试版: 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

    【讨论】:

      【解决方案2】:

      我通过将复杂类型声明添加到部分类并使用 [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

      【讨论】:

        猜你喜欢
        • 2016-04-08
        • 2021-04-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-04-17
        • 2016-09-08
        • 1970-01-01
        相关资源
        最近更新 更多