我想我错过了获取WCF数据服务/ OData /继承工作的技巧;我创建了几个简单的表格:
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')
将它们拉成edmx,用继承1替换自动创建的关系,生成:
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
}
设置使用V3的服务:
namespace WebApplication3
{
public class WcfDs : DataService<Entities>
{
public static void InitializeService(DataServiceConfiguration config)
{
config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
}
}
}
查询超级玩家工作正常:
http://localhost:8384/WcfDs.svc/Supers
我尝试了大量的网址,徒劳地尝试获取派生类型:
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/
....
但我总是得到404资源未找到的回复。我错过了什么?
答案 0 :(得分:3)
诀窍是:
从使用Visual Studio开发服务器切换到项目属性中使用本地IIS。
至少,这在我的VS 2010环境中有效。