public void TestFilterVisitor() { ODataConventionModelBuilder builder = new ODataConventionModelBuilder(); builder.EntitySet <Bar>("Bar"); ODataQueryContext context = new ODataQueryContext(builder.GetEdmModel(), typeof(Bar)); //ODataQueryOptions<Customer> query = new ODataQueryOptions<Customer>(context, new HttpRequestMessage(HttpMethod.Get, "http://server/?$top=10")); FilterQueryOption f = new FilterQueryOption("startswith(BarString,'b') eq true", context); var pathsString = FindNavigationFilterOptions.GetPaths(f).ToList(); CollectionAssert.AreEqual(pathsString, new string[0]); f = new FilterQueryOption("F/FooId eq 1", context); pathsString = FindNavigationFilterOptions.GetPaths(f).ToList(); CollectionAssert.AreEqual(pathsString, new[] { "F" }); f = new FilterQueryOption("Foos/any(x1: x1/B/BarId eq 1)", context); pathsString = FindNavigationFilterOptions.GetPaths(f).ToList(); CollectionAssert.AreEqual(pathsString, new[] { "Foos.B" }); f = new FilterQueryOption("(startswith(BarString,'b') eq true) and (not (Foos/any(x1: x1/B/BarId eq 1)))", context); pathsString = FindNavigationFilterOptions.GetPaths(f).ToList(); CollectionAssert.AreEqual(pathsString, new[] { "Foos.B" }); f = new FilterQueryOption("Foos/any(x1: x1/B/F/FooId eq 1)", context); pathsString = FindNavigationFilterOptions.GetPaths(f).ToList(); CollectionAssert.AreEqual(pathsString, new[] { "Foos.B.F" }); f = new FilterQueryOption("F/Bars/any(x1: x1/BarId eq 1)", context); pathsString = FindNavigationFilterOptions.GetPaths(f).ToList(); CollectionAssert.AreEqual(pathsString, new[] { "F.Bars" }); f = new FilterQueryOption("F/Bars/any(x1: ((x1/BarId eq 1) and (x1/BarString eq 'abc')) and (x1/F/FooId lt 3))", context); pathsString = FindNavigationFilterOptions.GetPaths(f).ToList(); CollectionAssert.AreEqual(pathsString, new[] { "F.Bars.F" }); }
public IncludeSelectOptions(ODataQueryOptions options) { var se = options.SelectExpand; if (se != null) { if (se.RawExpand != null) { Includes = se.RawExpand.Split(splitter); } if (se.RawSelect != null) { Selects = se.RawSelect.Split(splitter); } } if (options.Filter != null) { var navs = FindNavigationFilterOptions.GetPaths(options.Filter, Seperator.ToString()); if (navs.Any()) { Includes = (Includes ?? new string[0]).Union(navs).ToArray(); } } if (options.OrderBy != null) { var orderProps = new HashSet <string>(Includes ?? new string[0]); foreach (var n in options.OrderBy.RawValue.Split(splitter)) { int i = n.LastIndexOf(Seperator); if (i > -1) { orderProps.Add(n.Substring(0, i)); } } Includes = orderProps.ToArray(); } }