WCF RIA Services - returning custom class of two already defined classes

我与影子孤独终老i 提交于 2019-12-24 01:39:26

问题


I have a Silverlight / WCF RIA Services application that uses EF 4. Currently, there is a domain service that returns two types of classes, OrderItem and Event. I'd like to create a class that contains both of these items for easier manipulation of the data at the XAML level. Here is what the class that combines the two classes looks like:

[Serializable]
[DataContract]
public partial class EventOrderItem  {
    [Key]
    [DataMember]
    public string EventOrderItemKey { get { return Event.EventID.ToString() + "-" + OrderItem.OrderItemID.ToString(); } }

    [DataMember]
    public Event Event { get; set; }

    [DataMember]
    public OrderItem OrderItem { get; set; }
}

The domain service returns the EventOrderItem, but the Event and OrderItem properties are not present on the class. How do I get RIA Services to pick up on these two properties?


回答1:


As per your comment, unfortunately it's not possible (it's one of my biggest bugbears with RIA Services). According to the RIA Services UserVoice site (http://dotnet.uservoice.com/forums/57026-wcf-ria-services) they're working on enabling complex types now, but for the time being you're out of luck :(.

Hope this helps...

Chris




回答2:


I've managed to get this working in a similar scenario in my application by making use of the [Include] and [Association] attributes on the included types. I'm using POCO objects instead of EF4, though, so your mileage may vary.



来源:https://stackoverflow.com/questions/3988738/wcf-ria-services-returning-custom-class-of-two-already-defined-classes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!