当前位置: 首页>>代码示例>>C#>>正文


C# ODataConventionModelBuilder.AddEntityType方法代码示例

本文整理汇总了C#中ODataConventionModelBuilder.AddEntityType方法的典型用法代码示例。如果您正苦于以下问题:C# ODataConventionModelBuilder.AddEntityType方法的具体用法?C# ODataConventionModelBuilder.AddEntityType怎么用?C# ODataConventionModelBuilder.AddEntityType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ODataConventionModelBuilder的用法示例。


在下文中一共展示了ODataConventionModelBuilder.AddEntityType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Apply_KeyNameConventions_Works

        public void Apply_KeyNameConventions_Works()
        {
            // Arrange
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();

            EntityTypeConfiguration principalEntity = builder.AddEntityType(typeof(DiscoveryPrincipalEntity));
            PropertyInfo propertyInfo = typeof(DiscoveryPrincipalEntity).GetProperty("DiscoveryPrincipalEntityId");
            principalEntity.HasKey(propertyInfo);

            EntityTypeConfiguration dependentEntity = builder.AddEntityType(typeof(DiscoveryDependentEntity));
            PropertyInfo expectPropertyInfo = typeof(DiscoveryDependentEntity).GetProperty("DiscoveryPrincipalEntityId");
            dependentEntity.AddProperty(expectPropertyInfo);

            PropertyInfo navigationPropertyInfo = typeof(DiscoveryDependentEntity).GetProperty("Principal");
            NavigationPropertyConfiguration navigation = dependentEntity.AddNavigationProperty(navigationPropertyInfo,
                EdmMultiplicity.One);
            navigation.AddedExplicitly = false;

            // Act
            new ForeignKeyDiscoveryConvention().Apply(navigation, dependentEntity, builder);

            // Assert
            PropertyInfo actualPropertyInfo = Assert.Single(navigation.DependentProperties);
            Assert.Same(expectPropertyInfo, actualPropertyInfo);

            PropertyInfo principalProperty = Assert.Single(navigation.PrincipalProperties);
            Assert.Equal("DiscoveryPrincipalEntityId", principalProperty.Name);
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:28,代码来源:ForeignKeyDiscoveryConventionTest.cs

示例2: Apply_TypeNameConventions_Works

        public void Apply_TypeNameConventions_Works(string propertyName, EdmMultiplicity multiplicity, bool optional)
        {
            // Arrange
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();

            EntityTypeConfiguration principalEntity = builder.AddEntityType(typeof(DiscoveryPrincipalEntity));
            PropertyInfo propertyInfo = typeof(DiscoveryPrincipalEntity).GetProperty(propertyName);
            principalEntity.HasKey(propertyInfo);

            EntityTypeConfiguration dependentEntity = builder.AddEntityType(typeof(DiscoveryDependentEntity));
            PropertyInfo expectPropertyInfo = typeof(DiscoveryDependentEntity).GetProperty("DiscoveryPrincipalEntity" + propertyName);
            var property = dependentEntity.AddProperty(expectPropertyInfo);

            PropertyInfo navigationPropertyInfo = typeof(DiscoveryDependentEntity).GetProperty("Principal");
            NavigationPropertyConfiguration navigation = dependentEntity.AddNavigationProperty(navigationPropertyInfo, multiplicity);

            // Act
            new ForeignKeyDiscoveryConvention().Apply(navigation, dependentEntity, builder);

            // Assert
            PropertyInfo actualPropertyInfo = Assert.Single(navigation.DependentProperties);
            Assert.Same(expectPropertyInfo, actualPropertyInfo);

            PropertyInfo principalProperty = Assert.Single(navigation.PrincipalProperties);
            Assert.Equal(propertyName, principalProperty.Name);

            Assert.Equal(optional, property.OptionalProperty);
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:28,代码来源:ForeignKeyDiscoveryConventionTest.cs

示例3: Apply_SingleNullableForeignKeyOnNavigationProperty_Works

        public void Apply_SingleNullableForeignKeyOnNavigationProperty_Works()
        {
            // Arrange
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();

            builder.EntityType<PrincipalEntity>().HasKey(p => p.PrincipalIntId);
            EntityTypeConfiguration dependentEntity = builder.AddEntityType(typeof(SingleNullableDependentEntity));

            PropertyInfo expectPrincipal = typeof(PrincipalEntity).GetProperty("PrincipalIntId");
            PropertyInfo expectDependent = typeof(SingleNullableDependentEntity).GetProperty("PrincipalId");
            PrimitivePropertyConfiguration primitiveProperty = dependentEntity.AddProperty(expectDependent);

            PropertyInfo propertyInfo = typeof(SingleNullableDependentEntity).GetProperty("Principal");
            NavigationPropertyConfiguration navigation = dependentEntity.AddNavigationProperty(propertyInfo,
                EdmMultiplicity.ZeroOrOne);
            navigation.AddedExplicitly = false;

            // Act
            new ForeignKeyAttributeConvention().Apply(navigation, dependentEntity, builder);

            // Assert
            PropertyInfo actualPropertyInfo = Assert.Single(navigation.DependentProperties);
            Assert.Same(expectDependent, actualPropertyInfo);

            actualPropertyInfo = Assert.Single(navigation.PrincipalProperties);
            Assert.Same(expectPrincipal, actualPropertyInfo);

            Assert.True(primitiveProperty.OptionalProperty);
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:29,代码来源:ForeignKeyAttributeConventionTest.cs

示例4: Apply_Doesnot_Override_UserConfiguration

        public void Apply_Doesnot_Override_UserConfiguration()
        {
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
            var vehicles = builder.EntitySet<Vehicle>("vehicles");
            var car = builder.AddEntityType(typeof(Car));
            var paintAction = vehicles.EntityType.Action("Paint");
            paintAction.HasActionLink(ctxt => new Uri("http://localhost/ActionTestWorks"), followsConventions: false);
            ActionLinkGenerationConvention convention = new ActionLinkGenerationConvention();

            convention.Apply(paintAction, builder);

            IEdmModel model = builder.GetEdmModel();
            var vehiclesEdmSet = model.EntityContainer.FindEntitySet("vehicles");
            var carEdmType = model.FindDeclaredType("System.Web.OData.Builder.TestModels.Car") as IEdmEntityType;
            var paintEdmAction =
                model.GetAvailableProcedures(
                    model.FindDeclaredType("System.Web.OData.Builder.TestModels.Car") as IEdmEntityType).Single()
                as IEdmAction;
            Assert.NotNull(paintEdmAction);

            HttpConfiguration configuration = new HttpConfiguration();
            configuration.Routes.MapODataServiceRoute(model);

            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost");
            request.SetConfiguration(configuration);

            ActionLinkBuilder actionLinkBuilder = model.GetActionLinkBuilder(paintEdmAction);

            var serializerContext = new ODataSerializerContext { Model = model, NavigationSource = vehiclesEdmSet, Url = request.GetUrlHelper() };
            var entityContext = new EntityInstanceContext(serializerContext, carEdmType.AsReference(), new Car { Model = 2009, Name = "Contoso" });

            Uri link = actionLinkBuilder.BuildActionLink(entityContext);
            Assert.Equal("http://localhost/ActionTestWorks", link.AbsoluteUri);
        }
开发者ID:nicholaspei,项目名称:aspnetwebstack,代码行数:34,代码来源:ActionLinkGenerationConventionTest.cs

示例5: GetModel

        public override IEdmModel GetModel(Type elementClrType, HttpRequestMessage request,
            HttpActionDescriptor actionDescriptor)
        {
            // Get model for the request
            IEdmModel model = request.ODataProperties().Model;

            if (model == null)
            {
                // user has not configured anything or has registered a model without the element type
                // let's create one just for this type and cache it in the action descriptor
                model = actionDescriptor.Properties.GetOrAdd("System.Web.OData.Model+" + elementClrType.FullName, _ =>
                {
                    ODataConventionModelBuilder builder =
                        new ODataConventionModelBuilder(actionDescriptor.Configuration, isQueryCompositionMode: true);
                    builder.EnableLowerCamelCase();
                    EntityTypeConfiguration entityTypeConfiguration = builder.AddEntityType(elementClrType);
                    builder.AddEntitySet(elementClrType.Name, entityTypeConfiguration);
                    IEdmModel edmModel = builder.GetEdmModel();
                    Contract.Assert(edmModel != null);
                    return edmModel;
                }) as IEdmModel;
            }

            Contract.Assert(model != null);
            return model;
        }
开发者ID:tanjinfu,项目名称:WebApiODataSamples,代码行数:26,代码来源:MyEnableQueryAttribute.cs

示例6: DiscoverInheritanceRelationships_PatchesBaseType

        public void DiscoverInheritanceRelationships_PatchesBaseType()
        {
            var mockType1 = new MockType("Foo");
            var mockType2 = new MockType("Bar").BaseType(mockType1);
            var mockAssembly = new MockAssembly(mockType1, mockType2);

            HttpConfiguration configuration = new HttpConfiguration();
            configuration.Services.Replace(typeof(IAssembliesResolver), new TestAssemblyResolver(mockAssembly));
            var builder = new ODataConventionModelBuilder(configuration);

            var entity1 = builder.AddEntityType(mockType1);
            var entity2 = builder.AddEntityType(mockType2);

            builder.DiscoverInheritanceRelationships();

            Assert.Equal(entity1, entity2.BaseType);
        }
开发者ID:tlycken,项目名称:aspnetwebstack,代码行数:17,代码来源:ODataConventionModelBuilderTests.cs

示例7: EntityKeyConvention_DoesnotFigureOutKeyPropertyOnDerivedTypes

        public void EntityKeyConvention_DoesnotFigureOutKeyPropertyOnDerivedTypes()
        {
            MockType baseType =
                new MockType("BaseType")
                .Property<uint>("ID");

            MockType derivedType =
                new MockType("DerivedType")
                .Property<int>("DerivedTypeID")
                .BaseType(baseType);

            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
            builder.AddEntityType(derivedType).DerivesFrom(builder.AddEntityType(baseType));

            IEdmModel model = builder.GetEdmModel();

            IEdmEntityType baseEntity = model.AssertHasEntityType(baseType);
            baseEntity.AssertHasKey(model, "ID", EdmPrimitiveTypeKind.Int64);

            IEdmEntityType derivedEntity = model.AssertHasEntityType(derivedType);
            derivedEntity.AssertHasPrimitiveProperty(model, "DerivedTypeID", EdmPrimitiveTypeKind.Int32, isNullable: false);
        }
开发者ID:tlycken,项目名称:aspnetwebstack,代码行数:22,代码来源:EntityKeyConventionTests.cs

示例8: RequiredAttributeEdmPropertyConvention_ConfiguresRequiredPropertyAsRequired

        public void RequiredAttributeEdmPropertyConvention_ConfiguresRequiredPropertyAsRequired()
        {
            MockType type =
                new MockType("Entity")
                .Property(typeof(int), "ID")
                .Property(typeof(int?), "Count", new RequiredAttribute());

            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
            builder.AddEntityType(type);

            IEdmModel model = builder.GetEdmModel();
            IEdmEntityType entity = model.AssertHasEntityType(type);
            entity.AssertHasPrimitiveProperty(model, "Count", EdmPrimitiveTypeKind.Int32, isNullable: false);
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:14,代码来源:RequiredAttributeEdmPropertyConventionTests.cs

示例9: RequiredAttributeEdmPropertyConvention_DoesnotOverwriteExistingConfiguration

        public void RequiredAttributeEdmPropertyConvention_DoesnotOverwriteExistingConfiguration()
        {
            MockType type =
                new MockType("Entity")
                .Property(typeof(int), "ID")
                .Property(typeof(int), "Count", new RequiredAttribute());

            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
            builder.AddEntityType(type).AddProperty(type.GetProperty("Count")).IsOptional();

            IEdmModel model = builder.GetEdmModel();
            IEdmEntityType entity = model.AssertHasEntityType(type);
            entity.AssertHasPrimitiveProperty(model, "Count", EdmPrimitiveTypeKind.Int32, isNullable: true);
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:14,代码来源:RequiredAttributeEdmPropertyConventionTests.cs

示例10: EntityKeyConvention_FiguresOutTheKeyProperty

        public void EntityKeyConvention_FiguresOutTheKeyProperty()
        {
            MockType baseType =
                new MockType("BaseType")
                .Property<uint>("ID");

            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
            builder.AddEntityType(baseType);

            IEdmModel model = builder.GetEdmModel();

            IEdmEntityType entity = model.AssertHasEntityType(baseType);
            entity.AssertHasKey(model, "ID", EdmPrimitiveTypeKind.Int64);
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:14,代码来源:EntityKeyConventionTests.cs

示例11: Apply_DoesnotModifiy_ExplicitlyAddedAction

        public void Apply_DoesnotModifiy_ExplicitlyAddedAction()
        {
            // Arrange
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
            PropertyInfo propertyInfo = typeof(TestOrder).GetProperty("Customer");
            EntityTypeConfiguration entity = builder.AddEntityType(typeof(TestOrder));
            NavigationPropertyConfiguration navProperty = entity.AddNavigationProperty(propertyInfo, EdmMultiplicity.One);
            navProperty.OnDeleteAction = EdmOnDeleteAction.None;

            // Act
            new ActionOnDeleteAttributeConvention().Apply(navProperty, entity, builder);

            // Assert
            Assert.Equal(EdmOnDeleteAction.None, navProperty.OnDeleteAction);
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:15,代码来源:ActionOnDeleteAttributeConventionTest.cs

示例12: BuildEdmModel

        public static IEdmModel BuildEdmModel(Type ApiContextType)
        {
            ODataModelBuilder builder = new ODataConventionModelBuilder();
            builder.Namespace = ApiContextType.Namespace;

            var publicProperties = ApiContextType.GetProperties(BindingFlags.Public | BindingFlags.Instance);
            foreach (var property in publicProperties)
            {
                var entityClrType = TypeHelper.GetImplementedIEnumerableType(property.PropertyType);
                EntityTypeConfiguration entity = builder.AddEntityType(entityClrType);
                builder.AddEntitySet(property.Name, entity);
            }

            return builder.GetEdmModel();
        }
开发者ID:genusP,项目名称:WebApi,代码行数:15,代码来源:DefaultODataModelProvider.cs

示例13: Apply_DoesnotRemove_ExplicitlyAddedProperties

        public void Apply_DoesnotRemove_ExplicitlyAddedProperties()
        {
            // Arrange
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder() { ModelAliasingEnabled = false };
            PropertyInfo propertyInfo = typeof(TestEntity).GetProperty("ExplicitlyAddedProperty");
            EntityTypeConfiguration entity = builder.AddEntityType(typeof(TestEntity));
            PropertyConfiguration property = entity.AddProperty(propertyInfo);

            // Act
            _convention.Apply(entity, builder);

            // Assert
            Assert.Contains(propertyInfo, entity.ExplicitProperties.Keys);
            Assert.DoesNotContain(propertyInfo, entity.RemovedProperties);
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:15,代码来源:DataContractAttributeEdmTypeConventionTests.cs

示例14: Apply_DoesnotRemove_ExplicitlyAddedProperties

        public void Apply_DoesnotRemove_ExplicitlyAddedProperties()
        {
            // Arrange
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
            
            PropertyInfo propertyInfo = typeof(TestEntity).GetProperty("Property");
            EntityTypeConfiguration entity = builder.AddEntityType(typeof(TestEntity));
            PropertyConfiguration property = entity.AddProperty(propertyInfo);

            // Act
            new NotMappedAttributeConvention().Apply(property, entity, builder);

            // Assert
            Assert.Contains(propertyInfo, entity.ExplicitProperties.Keys);
            Assert.DoesNotContain(propertyInfo, entity.RemovedProperties);
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:16,代码来源:NotMappedAttributeConventionTests.cs

示例15: CreateImplicitModel

        private static IEdmModel CreateImplicitModel(HttpConfiguration configuration, Type elementClrType)
        {
            ODataConventionModelBuilder builder =
                new ODataConventionModelBuilder(configuration, isQueryCompositionMode: true);

            // Add the type to the model as an entity and add an entity set with the same name.
            EntityTypeConfiguration entityTypeConfiguration = builder.AddEntityType(elementClrType);
            builder.AddEntitySet(elementClrType.Name, entityTypeConfiguration);

            // Build the model and add the AuthorizedRolesAnnotation.
            IEdmModel edmModel = builder.GetEdmModel();
            Contract.Assert(edmModel != null);

            edmModel.AddAuthorizedRolesAnnotations();
            return edmModel;
        }
开发者ID:nickgoodrow,项目名称:ODataSamples,代码行数:16,代码来源:AuthorizationEnableQueryAttribute.cs


注:本文中的ODataConventionModelBuilder.AddEntityType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。