RIA POCO 中的嵌入对象?

发布于 2024-10-27 23:13:09 字数 807 浏览 6 评论 0原文

向所有 silverlight 爱好者提一个简单的问题..

我需要通过 ria 服务公开一个自定义 POCO 对象.. 好吧,我可能可以通过普通的 Web 服务来完成它.. 所以我不介意你告诉我通过非 RIA 服务来完成它

有点像这样:

public partial class Monkey
{
  // etc..
  // This is an entity framework entity
}

public class MonkeyCollection
{
  // This is the POCO
  public string MonthName { get; set; }
  public Monkey MonkeyForMonth1 { get; set; }
  public Monkey MonkeyForMonth2 { get; set; }

  // Keep RIA services quiet about the lack of a "key"
  [Key]
  public int ID { get; set; }
}

// In my service class
public IEnumerable<MonkeyCollection> GetMonkeys()
{
  // Churn the data like butter
}

这返回 POCO 的集合,但它不返回嵌入对象(猴子)。

即它返回基元(月份名称,id),但不返回自定义对象。

事实上,Visual Studio 中的智能感知似乎甚至不知道类上的这些属性。

我应该做什么?

谢谢

丹尼尔

Quick question for all y'all silverlight buffs..

I need to expose a custom POCO object through ria services.. Well kind of, i could probably get away with doing it over a vanilla web service.. so i dont mind if you tell me to do it over a non-RIA service

It's a bit like this:

public partial class Monkey
{
  // etc..
  // This is an entity framework entity
}

public class MonkeyCollection
{
  // This is the POCO
  public string MonthName { get; set; }
  public Monkey MonkeyForMonth1 { get; set; }
  public Monkey MonkeyForMonth2 { get; set; }

  // Keep RIA services quiet about the lack of a "key"
  [Key]
  public int ID { get; set; }
}

// In my service class
public IEnumerable<MonkeyCollection> GetMonkeys()
{
  // Churn the data like butter
}

This returns a collection of the POCO's but what it doesn't return is the embedded objects (monkey).

i.e. it returns the primitives (monthname, id) but not the custom objects..

And in fact intellisense in visual studio doesnt even seem to know about those properties on the class..

What should i do?

Thanks

Daniel

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

送你一个梦 2024-11-03 23:13:09

您需要 IncludeAttribute 和 AssociationAttribute。

public partial class Monkey
{
  // etc..
  // This is an entity framework entity

  // fill this with the ID of the collection
  public ParentMonkeyCollectionId { get; set; } 
}

public class MonkeyCollection
{
    // all the rest ...

    [Include]
    [Association("monkey1", "ID", "ParentMonkeyCollectionId")]
    public Monkey MonkeyForMonth1 { get; set; }

    [Include]
    [Association("monkey2", "ID", "ParentMonkeyCollectionId")]
    public Monkey MonkeyForMonth2 { get; set; }
}

请参阅此处了解类似案例和说明。

另请检查 WCF RIA 服务和 DTO 关联 了解更多详细信息。

You need the IncludeAttribute and the AssociationAttribute.

public partial class Monkey
{
  // etc..
  // This is an entity framework entity

  // fill this with the ID of the collection
  public ParentMonkeyCollectionId { get; set; } 
}

public class MonkeyCollection
{
    // all the rest ...

    [Include]
    [Association("monkey1", "ID", "ParentMonkeyCollectionId")]
    public Monkey MonkeyForMonth1 { get; set; }

    [Include]
    [Association("monkey2", "ID", "ParentMonkeyCollectionId")]
    public Monkey MonkeyForMonth2 { get; set; }
}

Look here for a similar case and the explanation.

Also check WCF RIA Services and DTO with association for more details.

怀里藏娇 2024-11-03 23:13:09

将其移至自己的网络服务中..感觉更干净!

Moved it into it's own web service.. Just feels cleaner!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文