Мое приложение расширялось до 4 уровней, которые были прекрасно настроены так, как было настроено все время, примерно до недели назад, а теперь даже с примерным расширением проекта останавливается на 3-м уровне. Вот мой метод OData GET и соответствующие отношения объектной модели, а файл webApiConfig.cs с максимальным значением MaxExpansionDepth равен 4.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