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).
ie 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.
将它移入它自己的网络服务中。只要感觉更干净!
链接地址: http://www.djcxy.com/p/34506.html上一篇: 实体框架中的POCO是什么?
下一篇: RIA POCO中的嵌入对象?