1

我想做一个包含实体的 DTO。我该怎么做?是否可以?

例如,我的服务器项目中有这样的东西:

public class MyCustomDTO
{   
    [Key]
    public int id { get; set; }

    public EntityCollection<MyEntity> list { get; set; }

    public MyEntity2 dummyproperty { get; set; }

    public string name{ get; set; }
}

但在客户端只生成基本类型,而不是集合和 MyEntity2 类型属性。

我的目标是将几个不同的实体封装到一个 DTO 中,而不是通过多个异步查询来收集它们......

或者有哪些不同的解决方案可能适合这种情况?我是否缺少某些东西(某些属性)或者它只是不受支持?

4

2 回答 2

0

您可以在 Silverlight 客户端和 WCF RIA 服务之间发送复杂类型,但您的 DTO 不能将 [Key] 属性应用于属性。

public class MyCustomDTO
{   
    //[Key] // comment this line and there you go.
    public int id { get; set; }

    public List<MyEntity> list { get; set; }

    public MyEntity2 dummyproperty { get; set; }

    public string name{ get; set; }
}

更新

您需要为 Silverlight 4 安装 WCF RIA Services V1.0 SP1,然后才能在应用程序中使用复杂类型。WCF RIA Services V1.0 SP1是关于此服务包中更改的好文章。

于 2011-10-29T18:47:38.147 回答
0

除了 DTO 之外,您还需要将其他实体公开为服务方法,以便 RIA 服务可以在客户端跟踪它们。您的服务应如下所示:

public class MyDomainService : LinqToEntitiesDomainService<MyContext>
{
    public IQueryable<MyCustomDto> GetMyCustomDtos()
    {
        //...
    }

    public IQueryable<MyEntity> GetMyEntitys()
    {
        //...
    }

    public IQueryable<MyEntity2> GetMyEntity2s()
    {
        //...
    }
}

您还需要将 [Include] 属性添加到您的实体,以便在客户端检索它们。

于 2012-02-21T11:55:21.263 回答