이 질문에 대한 답을 찾기 위해 주변을 둘러 보았으나 누구도 이렇게 정확한 문제에 직면 해 있다고 생각하지 않습니다. 정말 간단히, C#에서 반사 공급자를 사용하여 odata 서비스 (like so)를 만들고 두 엔티티 (블록 및 루트)를 갖습니다.Odata 네비게이션 속성으로 인해 404 오류가 발생했습니다.
블록은 파일 시스템의 파일 및 디렉토리와 비슷하며 일부 블록은 하위 블록을 가질 수 있으며 일부 블록은 파일을 가질 수 없습니다. 루트는 다른 사용자 계정과 같으며 장치는 하나의 루트에만 속할 수 있습니다. 여기에 지금까지 가지고 무엇을 : 아주 잘
Classes.cs
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.Data.Services.Common;
using System.Data.Services;
[DataServiceEntity]
public class Block
{
public string Name { set; get; }
public int ID { set; get; }
public int PID { set; get; }
}
public class ParentBlock : Block
{
public List<Block> Children { set; get; }
public int Count { get { return Children.Count(); } }
public ParentBlock()
{
Children = new List<Block>();
}
}
/*other classes that inherit from Block or ParentBlock*/
[DataServiceEntity]
[DataServiceKey("User")]
public class Root
{
public string User { set; get; }
public int ID { set; get; }
public List<Block> Children { set; get; }
public Root()
{
Children = new List<Block>();
}
}
Main.cs
[System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public class RootDataService : DataService<RootService>
{
public static void InitializeService(DataServiceConfiguration config)
{
config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
config.UseVerboseErrors = true;
config.DataServiceBehavior.MaxProtocolVersion = System.Data.Services.Common.DataServiceProtocolVersion.V2;
}
}
public class RootService
{
private List<Root> RootList = new List<Root>();
private List<Block> BlockList = new List<Block>();
public RootService()
{
/*initializes RootList and BlockList with test data*/
}
public IQueryable<Root> Roots
{
get
{
return RootList.AsQueryable<Root>();
}
}
public IQueryable<Block> Blocks
{
get
{
return BlockList.AsQueryable<Block>();
}
}
}
이 모든 작동합니다. 프로그램을 실행하고 브라우저로 이동하면 두 개의 콜렉션 인 Roots와 블록을 얻습니다. odata/Roots ('account1')를 사용하여 첫 번째 계정의 사용자 및 ID를 가져올 수 있습니다. odata/Roots ('account1')/Children (5)을 수행하고 ID가 5 인 블록을 얻을 수 있습니다.
하지만 odata/Roots ('account1')/Children)/Children 또는 odata/Block (5)/Children, 나는 404를 얻는다. 나는 RootService
생성자에 검증 코드를 추가하고 Block 속성이 Block (5)에 자식 (2 개)이 있음을 보여 줘서 실망 스럽지만, 그들을 탐색 할 수 없습니까? 나는 분명히 내가 빠진 것이 분명하다고 확신하지만, 나는 그것을 발견하지 못했다. 더 많은 어리둥절한 점은 Root
과 ParentBlock
모두가 자신의 Children
목록을 외부 클래스에서 사용할 수 있도록하는 것과 동일한 코드를 가지고 있지만 그 중 하나만 탐색 할 수 있다는 것입니다. 어떤 도움을 주셔서 감사합니다!
단어가 흥분하는 것을 표현할 수 없습니다. 나는 캐스팅을 시도했으나 작동하지 않는 것 같았습니다. (아마도 네임 스페이스 또는 뭔가 잘못 입력되었음을 알 수 있습니다.) 처음에는 기본적으로 자식 목록을 기본 Block 클래스로 옮겼으며 Block에서 상속 한 모든 항목은 자식을 가질 수 있는지 여부를 나타내는 플래그 값을 토글해야합니다. 고마워요! – Alkeeros
도와 주셔서 감사합니다 :) –