开发者

Returning nested complex types from EF4 using Stored Procedures

Is it possible to return nested complex types from multiple different Stored Procedures using EF? (e.g. ClientSelect, ClientAddressSelect)

I have imported a few stored procedures and added function imports and created a Complex Type for each of the return types. (e.g. Client and ClientAddress).

Now, for example, I want to add the ClientAddress Complex Type to the Client complex type. I will return all values for Client using ClientSelect and then populate ClientAddress using ClientAddressSelect.

When I try to run ClientSelect I get the following error:

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

Which makes it look like this isn't possible, is there another way round this? I'm using WCF RIA Ser开发者_StackOverflowvices and would like to populate the full Client object on the server side before sending it to the Silverlight client.

Any help/suggestions appreciated.


The latest RIA Services SP1 (just released as a BETA) now supports complex types. You might want to consider it as we found it also solves a number of problems with RIA services.

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

WCF RIA Services Toolkit October 2010: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=a23325ef-7b1f-4c92-9fd5-ffee48f7c7bc


I resolved this issue by adding the Complex Type declaration into a partial class and using the [Include] and [Associate] attributes.

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; }
}

I then call a SP to populate Client, and then a seperate stored procedure to populate Client.Addresses

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜