2016-11-08 14 views
0

내 응용 프로그램은 약 1 주일 전까지 구성되어 있으므로 4 단계로 확장되었으며 이제는 샘플 프로젝트를 확장해도 3 단계에서 중단됩니다. 여기 내 OData GET 메소드와 해당 객체 모델 관계 및 MaxExpansionDepth가 4로 설정된 MaxApansionDepth를 보여주는 webApiConfig.cs 파일이 있습니다.OData v4는 세 번째 깊이 이상으로 확장을 멈 춥니 다.

어디서나 도움을 찾을 수 없으므로이 이상한 갑작스러운 동작에 대한 귀하의 의견을 보내 주시면 감사하겠습니다. .

[HttpGet] 
[ODataRoute("RotationSets")] 
public IQueryable<RotationSet> Get() 
{ 
    var rotationSets = new List<RotationSet>() 
    { 
     new RotationSet() 
     { 
      Id = 1, 
      Title = "RS 1", 
      Flights = new List<Flight>() 
      { 
       new Flight() 
       { 
        Id = 11, 
        StartDate = DateTime.Now, 
        EndDate = DateTime.Now.AddDays(2), 
        SpotRotations = new List<SpotRotation>() 
        { 
         new SpotRotation() 
         { 
          Id = 111, 
          Code = "123", 
          Spots = new List<Spot>() 
          { 
           new Spot() 
           { 
            Id = 1111, 
            StartDate = DateTime.Now.AddMonths(1), 
            EndDate = DateTime.Now.AddMonths(2), 
            Title = "Spot 1" 
           } 
          } 
         } 
        } 
       } 
      } 
     } 
    }; 

    return rotationSets.AsQueryable(); 
} 

public class RotationSet 
{ 
    public int Id { get; set; } 

    public string Title { get; set; } 

    public ICollection<Flight> Flights { get; set; } 

    public RotationSet() 
    { 
     Flights = new List<Flight>(); 
    } 
} 

public class Flight 
{ 
    public int Id { get; set; } 

    public DateTime StartDate { get; set; } 

    public DateTime EndDate { get; set; } 

    public ICollection<SpotRotation> SpotRotations { get; set; } 

    public Flight() 
    { 
     SpotRotations = new List<SpotRotation>(); 
    } 
} 

public class SpotRotation 
{ 
    public int Id { get; set; } 

    public string Code { get; set; } 

    public ICollection<Spot> Spots { get; set; } 

    public SpotRotation() 
    { 
     Spots = new List<Spot>(); 
    } 
} 

public class Spot 
{ 
    public int Id { get; set; } 

    public string Title { get; set; } 

    public DateTime StartDate { get; set; } 

    public DateTime EndDate { get; set; } 

} 


public static class WebApiConfig 
{ 
    public static HttpConfiguration Configure() 
    { 
     // Web API configuration and services 
     var config = new HttpConfiguration(); 

     var jsonFormatter = config.Formatters.OfType<JsonMediaTypeFormatter>().First(); 
     jsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); 
     jsonFormatter.SerializerSettings.PreserveReferencesHandling = PreserveReferencesHandling.None; 
     jsonFormatter.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; 
     jsonFormatter.SerializerSettings.Converters.Add(new StringEnumConverter()); 

     // No XML here. 
     config.Formatters.Remove(config.Formatters.XmlFormatter); 

     config.EnableCors(new EnableCorsAttribute("*", "*", "*")); 

     // Web API routes 
     config.MapHttpAttributeRoutes(); // Must be first. 

     config.EnableEnumPrefixFree(true); 

     config.MapODataServiceRoute("ODataRoute", "odata", GetEdmModel()); 

     //routeTemplate: "api/{controller}/{id}", 
     config.Routes.MapHttpRoute(
      name: "DefaultApi", 
      routeTemplate: "{controller}/{action}/{id}", 
      defaults: new { id = RouteParameter.Optional } 
     ); 

     var maxDepth = int.Parse(ConfigurationManager.AppSettings["ODataMaxExpandDepth"], CultureInfo.InvariantCulture); 
     var maxNodeCount = int.Parse(ConfigurationManager.AppSettings["ODataMaxNodeCount"], CultureInfo.InvariantCulture); 

     config.Filters.Add(new CacheControlAttribute()); 
     config.AddODataQueryFilter(new EnableQueryAttribute() 
     { 
      PageSize = 100, //int.Parse(ConfigurationManager.AppSettings["ODataMaxPageSize"], CultureInfo.InvariantCulture), 
      MaxNodeCount = 100, 
      MaxExpansionDepth = 4, 
      MaxAnyAllExpressionDepth = 4, 
      AllowedArithmeticOperators = AllowedArithmeticOperators.None, 
      AllowedFunctions = AllowedFunctions.AllFunctions, 
      AllowedQueryOptions = AllowedQueryOptions.Count | 
            AllowedQueryOptions.Expand | 
            AllowedQueryOptions.Filter | 
            AllowedQueryOptions.OrderBy | 
            AllowedQueryOptions.Select | 
            AllowedQueryOptions.Skip | 
            AllowedQueryOptions.Top | 
            AllowedQueryOptions.Format 
     }); 

     return config; 
    } 

    private static IEdmModel GetEdmModel() 
    { 
     var builder = new ODataConventionModelBuilder(); 

     builder.EntitySet<RotationSet>("RotationSets"); 

     builder.EnableLowerCamelCase(); 

     return builder.GetEdmModel(); 
    } 
} 
+0

안녕하세요, 아무도이에 대한 답변이 없습니다? – Ninos

답변

0

사용이 최대 깊이를 대체하기 위해 컨트롤러 액션에 쿼리를 사용 ...

[EnableQuery(MaxExpansionDepth = 23)] 
[HttpGet] 
[ODataRoute("RotationSets")] 
public IQueryable<RotationSet> Get() { ... } 
+0

다음과 같이 WebApiConfig.cs에서 MaxExpansionDepth를 설정 중이며 maxDepth가 미친 값으로 설정되어 있지만 제안 사항을 시도했지만 변경하지 않았습니다. config.AddODataQueryFilter (새 EnableQueryAttribute() { 페이지 크기 = int.Parse (ConfigurationManager.AppSettings [ "ODataMaxPageSize", CultureInfo.InvariantCulture) MaxNodeCount = maxNodeCount, MaxExpansionDepth = MAXDEPTH, MaxAnyAllExpressionDepth = MAXDEPTH, AllowedArithmeticOperators = AllowedArithmeticOperators.None, – Ninos

+0

불행히도 지금 당장 OData를 사용하지 말고 일반 API를 사용하십시오. – Ninos

+0

EF 엔티티에 직접 바인딩하는 경우 이와 같은 방식으로 작동한다고 생각하지 않습니다. 상속 같이 나는 그것 같이 재료를 피하고 간단한 DTO에 유지하는 것이 최상다는 것을 것을을 발견했다 – War