开发者

Embedded object in RIA POCO?

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


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.


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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜