Esempio n. 1
0
        public static IEdmModel GetEdmModel(HttpConfiguration configuration)
        {
            var builder = new ODataConventionModelBuilder(configuration);

            builder.EntitySet <Customer>("Customers");
            builder.EntitySet <Order>("Orders");
            IEdmModel model = builder.GetEdmModel();

            var stdDevMethods = getCustomMethods(typeof(DbFunctions), StdDevMethodLabel);
            CustomAggregateMethodAnnotation customMethods = new CustomAggregateMethodAnnotation();

            customMethods.AddMethod(StdDevMethodToken, stdDevMethods);

            model.SetAnnotationValue(model, customMethods);

            return(model);
        }
Esempio n. 2
0
        public static IEdmModel GetEdmModel(WebRouteConfiguration configuration)
        {
            var builder = configuration.CreateConventionModelBuilder();

            builder.EntitySet <Customer>("Customers");
            builder.EntityType <Customer>().EnumProperty(c => c.Bucket);
            builder.EntitySet <Order>("Orders");
            IEdmModel model = builder.GetEdmModel();

            var stdDevMethods = GetCustomMethods(typeof(DbFunctions), StdDevMethodLabel);
            CustomAggregateMethodAnnotation customMethods = new CustomAggregateMethodAnnotation();

            customMethods.AddMethod(StdDevMethodToken, stdDevMethods);

            model.SetAnnotationValue(model, customMethods);

            return(model);
        }
Esempio n. 3
0
        private static IEdmModel GetEdmModel()
        {
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();

            builder.Namespace     = "ODataAggregationSample";
            builder.ContainerName = "DefaultContainer";

            builder.EntitySet <Person>("People");
            var edmModel = builder.GetEdmModel() as EdmModel;

            var totalAgeMethod = GetCustomMethods(typeof(Person), "TotalAge");

            CustomAggregateMethodAnnotation customMethods = new CustomAggregateMethodAnnotation();

            customMethods.AddMethod("People.TotalAge", totalAgeMethod);
            edmModel.SetAnnotationValue(edmModel, customMethods);

            return(edmModel);
        }
Esempio n. 4
0
        public void CustomAggregateMethodAnnotation_Works_RoundTrip()
        {
            // Arrange
            MethodInfo methodInfo = new Mock <MethodInfo>().Object;

            IDictionary <Type, MethodInfo> methods = new Dictionary <Type, MethodInfo>
            {
                { typeof(int), methodInfo }
            };

            CustomAggregateMethodAnnotation annotation = new CustomAggregateMethodAnnotation();

            // Act & Assert
            annotation.AddMethod("token", methods);

            Assert.True(annotation.GetMethodInfo("token", typeof(int), out MethodInfo actual));
            Assert.Same(methodInfo, actual);

            Assert.False(annotation.GetMethodInfo("unknown", typeof(int), out _));
        }