I think I'm missing a trick getting WCF data services/OData/Inheritance working; I've created a couple of simple tables:
create table Super
(
superID int IDENTITY(1,1) not null PRIMARY KEY,
supername nvarchar(55),
)
create table sub
(
superID int not null,
extraData nvarchar(100),
FOREIGN KEY (superID) REFERENCES Super(superID)
)
insert Super values('abc')
insert Super values('def')
insert Super values('ghi')
insert Super values('jkl')
insert Super values('mno')
insert sub values(1, 'pqrstu')
insert sub values(3, 'vwxyz')
Pulled them into an edmx, replaced the relationship auto created with an inheritance one, which generates:
namespace WebApplication3
{
#region Contexts
public partial class Entities : ObjectContext
{ .... }
#endregion
#region Entities
[EdmEntityTypeAttribute(NamespaceName="Model", Name="sub")]
[Serializable()]
[DataContractAttribute(IsReference=true)]
public partial class sub : Super
{
#region Factory Method
...
#endregion
#region Primitive Properties
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
[DataMemberAttribute()]
public global::System.String extraData
...
#endregion
}
[EdmEntityTypeAttribute(NamespaceName="Model", Name="Super")]
[Serializable()]
[DataContractAttribute(IsReference=true)]
[KnownTypeAttribute(typeof(sub))]
public partial class Super : EntityObject
{
#region Factory Method
...
#endregion
#region Primitive Properties
[EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
[DataMemberAttribute()]
public global::System.Int32 superID
...
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
[DataMemberAttribute()]
public global::System.String supername
...
#endregion
}
#endregion
}
set up the service to use V3:
namespace WebApplication3
{
public class WcfDs : DataService<Entities>
{
public static void InitializeService(DataServiceConfiguration config)
{
config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
}
}
}
Querying the Supers works fine :
http://localhost:8384/WcfDs.svc/Supers
I've tried a host of URLs in a vain attempt to get the derived types:
http://localhost:8384/WcfDs.svc/Supers/Model.sub/
http://localhost:8384/WcfDs.svc/Supers(1)/Model.sub/
http://localhost:8384/WcfDs.svc/Supers/WebApplication3.sub/
http://localhost:8384/WcfDs.svc/Supers(1)/WebApplication3.sub/
....
but I always get a 404 Resource not found response. What am I missing?
And the trick is:
Switch from using the Visual Studio Development server to use the Local IIS in the project properties.
At least, this worked in my VS 2010 environment.