Search code examples
wcfwcf-data-serviceswcf-client

Entity Framework Computed Property not showing in Odata Feed


Im trying to add a "computed property"/"calculated property" to one of my tables in my entity framework model. I have the following Contact Partial Class:

Partial Public Class Contact
Public ReadOnly Property Tester As String
    Get
        Return "Tester"
    End Get
End Property
End Class

The problem I have is that when I run the odata.svc and query for Contacts, my tester property is never shown. I've put a breakpoint on it and it never enters the getter. I added a new constructor to the Partial class as follows to see if it is being executed:

Public Sub New()

End Sub

I put a breakpoint on the new constructor and this hits when Contacts are retrieved. So it seems like the partial class is defined correctly, it's just my calculated property is not being serialized to the odata feed.

Any ideas why?

Thanks


Solution

  • With EF based WCF Data Service, the server will only expose properties defined in the EF model, the properties on the CLR classes used on the server are not inspected to list the properties to write, only the model determines that list. There might be a way in EF to define the property as part of the model, in which case it should show up.