使用 WCF 数据服务 4.0,我无法返回分层数据。我有一个 Employee 类,它有一个 EquipmentIds 的集合。那些 EquipmentIds 正在通过网络丢失。这是我的代码:
public class ODataV2 : DataService<ODataV2Model>
{
public static void InitializeService(DataServiceConfiguration config)
{
config.UseVerboseErrors = true;
config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
}
}
public class ODataV2Model
{
public ODataV2Model()
{
Employees = new List<Employee>{
new Employee { Id = 1, Name="Doug", EquipmentIds = new List<Equipment> { new Equipment { Id = 1 },new Equipment { Id = 2 } }.AsQueryable()},
new Employee { Id = 2, Name= "George", EquipmentIds = new List<Equipment> {new Equipment { Id = 3}, new Equipment { Id = 5} }.AsQueryable() }
}.AsQueryable();
}
public IQueryable<Employee> Employees { get; private set; }
public IQueryable<Equipment> EquipmentIds { get; private set; }
}
[DataServiceKey("Id")]
public class Employee
{
public int Id { get; set; }
public string Name { get; set; }
public IQueryable<Equipment> EquipmentIds { get; set; }
}
[DataServiceKey("Id")]
public class Equipment
{
public int Id { get; set; }
}
当我在上面运行 LinqPad 时,我得到了这个:
我应该拥有两个计数为 2 的 EquipmentIds 集合,但我有 0。我没有收到错误,但数据永远不会到达客户端。
我切换到 WCF Data Services v 5.0,它在 .NET 端成功运行,但我失去了使用 LinqPad 查询的能力。有没有办法在 v 4.0 中工作?
如果没有,有没有办法升级 LinqPad 以识别 odata v3(WCF 数据服务 5.0)?