내 응용 프로그램은 약 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();
}
}
안녕하세요, 아무도이에 대한 답변이 없습니다? – Ninos