Esempio n. 1
0
        public static IEdmModel CreateModel(ApiModelBuilder apiModel)
        {
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();

            foreach (var entityTypeConfig in apiModel.GetEntityTypeConfigs())
            {
                EntityTypeConfiguration odataEntityTypeConfig = builder.AddEntity(entityTypeConfig.Type);

                foreach (var ignoredPropertyInfo in entityTypeConfig.GetIgnoredProperties())
                {
                    odataEntityTypeConfig.RemoveProperty(ignoredPropertyInfo);
                }
            }

            return(builder.GetEdmModel());
        }
Esempio n. 2
0
        public static void OnModelCreating(DbModelBuilder modelBuilder, Type contextProviderType)
        {
            ApiModelBuilder apiModel = ModelCache.GetApiModel(contextProviderType);

            // Ignore all entities not part of the API model
            modelBuilder.Ignore(apiModel.GetIgnoredEntityTypes());

            // Explicitly ignored properties
            foreach (var entityTypeConfig in apiModel.GetEntityTypeConfigs())
            {
                foreach (PropertyInfo propertyInfo in entityTypeConfig.GetIgnoredProperties())
                {
                    // Call the Ignore method below with the type parameters for this PropertyInfo
                    IgnoreMethodInfo.MakeGenericMethod(entityTypeConfig.Type, propertyInfo.PropertyType).Invoke(
                        null, new object[] { modelBuilder, propertyInfo });
                }
            }
        }