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


C# EntityType.AddProperty方法代码示例

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


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

示例1: EntityType

 public static EntityType EntityType()
 {
     var entityType = new EntityType(typeof(NullablePoco));
     entityType.AddProperty("NullInt", typeof(int?));
     entityType.AddProperty("NullDouble", typeof(double?));
     return entityType;
 }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:7,代码来源:SimpleTestTypes.cs

示例2: Get_generation_property_returns_generation_property_from_foreign_key_tree

        public void Get_generation_property_returns_generation_property_from_foreign_key_tree()
        {
            var model = new Model();

            var leftType = new EntityType("Left", model);
            var leftId = leftType.AddProperty("Id", typeof(int), true);
            var leftKey = leftType.AddKey(leftId);

            var rightType = new EntityType("Right", model);
            var rightId1 = rightType.AddProperty("Id1", typeof(int), true);
            var rightId2 = rightType.AddProperty("Id2", typeof(int), true);
            var rightKey = rightType.AddKey(new[] { rightId1, rightId2 });

            var middleType = new EntityType("Middle", model);
            var middleProperty1 = middleType.AddProperty("FK1", typeof(int), true);
            var middleProperty2 = middleType.AddProperty("FK2", typeof(int), true);
            var middleKey1 = middleType.AddKey(middleProperty1);
            var middleFK1 = middleType.AddForeignKey(middleProperty1, leftKey, leftType);
            var middleFK2 = middleType.AddForeignKey(new[] { middleProperty2, middleProperty1 }, rightKey, rightType);

            var endType = new EntityType("End", model);
            var endProperty = endType.AddProperty("FK", typeof(int), true);

            var endFK = endType.AddForeignKey(endProperty, middleKey1, middleType);

            rightId2.RequiresValueGenerator = true;

            Assert.Equal(rightId2, endProperty.GetGenerationProperty());
        }
开发者ID:JamesWang007,项目名称:EntityFramework,代码行数:29,代码来源:PropertyExtensionsTest.cs

示例3: TableEntityAdapterFactoryTests

 public TableEntityAdapterFactoryTests()
 {
     _factory = new TableEntityAdapterFactory();
     _entityType = new EntityType(typeof(PocoTestType));
     _entityType.AddProperty("PartitionKey", typeof(string));
     _entityType.AddProperty("RowKey", typeof(string));
     _entityType.AddProperty("Timestamp", typeof(DateTime));
 }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:8,代码来源:TableEntityAdapterFactoryTests.cs

示例4: Can_create_key_from_properties

        public void Can_create_key_from_properties()
        {
            var entityType = new EntityType("E");
            var property1 = entityType.AddProperty(Customer.IdProperty);
            var property2 = entityType.AddProperty(Customer.NameProperty);

            var key = new Key(new[] { property1, property2 });

            Assert.True(new[] { property1, property2 }.SequenceEqual(key.Properties));
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:10,代码来源:KeyTest.cs

示例5: Select_throws_when_composite_key

        public void Select_throws_when_composite_key()
        {
            var selector = CreateSelector();
            var entityType = new EntityType("Entity");
            var property = entityType.AddProperty("Id1", typeof(long));
            property.ValueGenerationOnAdd = ValueGenerationOnAdd.Client;
            entityType.SetKey(property, entityType.AddProperty("Id2", typeof(long)));

            Assert.Throws<NotSupportedException>(() => selector.Select(property));
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:10,代码来源:SQLiteValueGeneratorSelectorTest.cs

示例6: IsRequired_when_dependent_property_nullable

        public void IsRequired_when_dependent_property_nullable()
        {
            var entityType = new EntityType("E");
            entityType.SetKey(entityType.AddProperty("Id", typeof(int)));
            var dependentProp = entityType.AddProperty("P", typeof(int?));

            var foreignKey = new ForeignKey(entityType.GetKey(), new[] { dependentProp });

            Assert.False(foreignKey.IsRequired);
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:10,代码来源:ForeignKeyTest.cs

示例7: WithType

 public TestStateEntry WithType(string name)
 {
     var e = new EntityType(name);
     e.AddProperty("PartitionKey", typeof(string), true, false);
     e.AddProperty("RowKey", typeof(string), true, false);
     e.AddProperty("ETag", typeof(string), true, false);
     e.AddProperty("Timestamp", typeof(DateTime), true, false);
     _entityType = e;
     return this;
 }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:10,代码来源:TestStateEntry.cs

示例8: Can_create_unique_index_from_properties

        public void Can_create_unique_index_from_properties()
        {
            var entityType = new EntityType("E");
            var property1 = entityType.AddProperty(Customer.IdProperty);
            var property2 = entityType.AddProperty(Customer.NameProperty);

            var index = new Index(new[] { property1, property2 }) { IsUnique = true, };

            Assert.True(new[] { property1, property2 }.SequenceEqual(index.Properties));
            Assert.True(index.IsUnique);
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:11,代码来源:IndexTest.cs

示例9: Can_add_and_remove_properties

        public void Can_add_and_remove_properties()
        {
            var entityType = new EntityType(typeof(Customer));

            var property1 = entityType.AddProperty(Customer.IdProperty);
            var property2 = entityType.AddProperty(Customer.NameProperty);

            Assert.True(new[] { property1, property2 }.SequenceEqual(entityType.Properties));

            entityType.RemoveProperty(property1);

            Assert.True(new[] { property2 }.SequenceEqual(entityType.Properties));
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:13,代码来源:EntityTypeTest.cs

示例10: Validates_properties_from_same_entity

        public void Validates_properties_from_same_entity()
        {
            var entityType = new EntityType("E");
            var property1 = entityType.AddProperty(Customer.IdProperty);
            var property2 = entityType.AddProperty(Customer.NameProperty);

            property1.EntityType = new EntityType("E1");
            property2.EntityType = new EntityType("E2");

            Assert.Equal(Strings.FormatInconsistentEntityType("properties"),
                Assert.Throws<ArgumentException>(
                    () => new Key(new[] { property1, property2 })).Message);
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:13,代码来源:KeyTest.cs

示例11: Reader_contains_nulls_for_unmatched_properties

        public void Reader_contains_nulls_for_unmatched_properties()
        {
            var entityType = new EntityType("TestType");
            entityType.AddProperty("Prop1", typeof(string));
            entityType.AddProperty("Prop2", typeof(int));
            var buffer = new AtsNamedValueBuffer(new Dictionary<string, EntityProperty>());
            var reader = _factory.Create(entityType, buffer);

            Assert.Equal(2, reader.Count);
            Assert.True(reader.IsNull(0));
            Assert.True(reader.IsNull(1));
            Assert.DoesNotThrow(() => reader.ReadValue<string>(0));
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:13,代码来源:AtsObjectArrayValueReaderFactoryTests.cs

示例12: It_adds_composite_key

        public void It_adds_composite_key()
        {
            var entityType = new EntityType("John Maynard");
            entityType.AddProperty("PartitionKey", typeof(string));
            entityType.AddProperty("RowKey", typeof(string));

            _convention.Apply(entityType);

            var key = entityType.GetKey();
            Assert.Equal(2, key.Properties.Count);
            Assert.Contains("PartitionKey", key.Properties.Select(p => p.ColumnName()));
            Assert.Contains("RowKey", key.Properties.Select(p => p.ColumnName()));
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:13,代码来源:PartitionAndRowKeyConventionTests.cs

示例13: Delegate_getter_is_returned_for_IProperty_property

        public void Delegate_getter_is_returned_for_IProperty_property()
        {
            var entityType = new EntityType(typeof(Customer));
            var idProperty = entityType.AddProperty("Id", typeof(int));

            Assert.Equal(7, new ClrPropertyGetterSource().GetAccessor(idProperty).GetClrValue(new Customer { Id = 7 }));
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:7,代码来源:ClrPropertyGetterSourceTest.cs

示例14: Members_check_arguments

        public void Members_check_arguments()
        {
            Assert.Equal(
                "type",
                // ReSharper disable once AssignNullToNotNullAttribute
                Assert.Throws<ArgumentNullException>(() => new EntityType((Type)null)).ParamName);

            Assert.Equal(
                "name",
                // ReSharper disable once AssignNullToNotNullAttribute
                Assert.Throws<ArgumentNullException>(() => new EntityType((string)null)).ParamName);

            var entityType = new EntityType(typeof(Random));

            Assert.Equal(
                "propertyInfo",
                // ReSharper disable once AssignNullToNotNullAttribute
                Assert.Throws<ArgumentNullException>(() => entityType.AddProperty((PropertyInfo)null)).ParamName);

            Assert.Equal(
                "property",
                // ReSharper disable once AssignNullToNotNullAttribute
                Assert.Throws<ArgumentNullException>(() => entityType.RemoveProperty(null)).ParamName);

            Assert.Equal(
                Strings.FormatArgumentIsEmpty("name"),
                Assert.Throws<ArgumentException>(() => entityType.TryGetProperty("")).Message);

            Assert.Equal(
                Strings.FormatArgumentIsEmpty("name"),
                Assert.Throws<ArgumentException>(() => entityType.GetProperty("")).Message);
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:32,代码来源:EntityTypeTest.cs

示例15: Can_create_materializer_for_entity_with_fields

        public void Can_create_materializer_for_entity_with_fields()
        {
            var entityType = new EntityType(typeof(SomeEntityWithFields));
            entityType.AddProperty("Id", typeof(int));
            entityType.AddProperty("Foo", typeof(string));
            entityType.AddProperty("Goo", typeof(Guid));

            var factory = new EntityMaterializerSource(new MemberMapper(new FieldMatcher())).GetMaterializer(entityType);

            var gu = Guid.NewGuid();
            var entity = (SomeEntityWithFields)factory(new ObjectArrayValueReader(new object[] { "Fu", gu, 77 }));

            Assert.Equal(77, entity.Id);
            Assert.Equal("Fu", entity.Foo);
            Assert.Equal(gu, entity.Goo);
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:16,代码来源:EntityMaterializerSourceTest.cs


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