本文整理汇总了C#中System.Data.Entity.ModelConfiguration.Configuration.Types.EntityTypeConfiguration.Property方法的典型用法代码示例。如果您正苦于以下问题:C# EntityTypeConfiguration.Property方法的具体用法?C# EntityTypeConfiguration.Property怎么用?C# EntityTypeConfiguration.Property使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.Entity.ModelConfiguration.Configuration.Types.EntityTypeConfiguration
的用法示例。
在下文中一共展示了EntityTypeConfiguration.Property方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Property_should_return_property_configuration_for_complex_type
public void Property_should_return_property_configuration_for_complex_type()
{
var entityConfiguration = new EntityTypeConfiguration<Fixture>();
Assert.NotNull(entityConfiguration.Property(f => f.Complex.Id));
}
示例2: Configure
internal override void Configure(
EdmAssociationType associationType, EdmAssociationEnd dependentEnd,
EntityTypeConfiguration entityTypeConfiguration)
{
if (!_dependentProperties.Any())
{
return;
}
var associationConstraint
= new EdmAssociationConstraint
{
DependentEnd = dependentEnd
};
var dependentProperties = _dependentProperties.AsEnumerable();
if (!IsFullySpecified)
{
var foreignKeys
= from p in _dependentProperties
select new
{
PropertyInfo = p,
entityTypeConfiguration.Property(new PropertyPath(p)).ColumnOrder
};
if ((_dependentProperties.Count > 1)
&& foreignKeys.Any(p => !p.ColumnOrder.HasValue))
{
var dependentKeys = dependentEnd.EntityType.DeclaredKeyProperties;
if ((dependentKeys.Count == _dependentProperties.Count)
&&
foreignKeys.All(fk => dependentKeys.Any(p => p.GetClrPropertyInfo().IsSameAs(fk.PropertyInfo))))
{
// The FK and PK sets are equal, we know the order
dependentProperties = dependentKeys.Select(p => p.GetClrPropertyInfo());
}
else
{
throw Error.ForeignKeyAttributeConvention_OrderRequired(entityTypeConfiguration.ClrType);
}
}
else
{
dependentProperties = foreignKeys.OrderBy(p => p.ColumnOrder).Select(p => p.PropertyInfo);
}
}
foreach (var dependentProperty in dependentProperties)
{
var property
= associationConstraint
.DependentEnd
.EntityType
.GetDeclaredPrimitiveProperty(dependentProperty);
if (property == null)
{
throw Error.ForeignKeyPropertyNotFound(
dependentProperty.Name, associationConstraint.DependentEnd.EntityType.Name);
}
associationConstraint.DependentProperties.Add(property);
}
associationType.Constraint = associationConstraint;
var principalEnd = associationType.GetOtherEnd(dependentEnd);
if (principalEnd.IsRequired())
{
associationType.Constraint.DependentProperties.Each(p => p.PropertyType.IsNullable = false);
}
}
示例3: Configure_should_configure_and_order_keys_when_keys_and_order_specified
public void Configure_should_configure_and_order_keys_when_keys_and_order_specified()
{
var entityType = new EntityType("E", "N", DataSpace.CSpace);
var property = EdmProperty.CreatePrimitive("P2", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
entityType.AddMember(property);
var property1 = EdmProperty.CreatePrimitive("P1", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
entityType.AddMember(property1);
var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object));
var mockPropertyInfo2 = new MockPropertyInfo(typeof(int), "P2");
entityTypeConfiguration.Key(mockPropertyInfo2);
entityTypeConfiguration.Property(new PropertyPath(mockPropertyInfo2)).ColumnOrder = 1;
(entityType.GetDeclaredPrimitiveProperties().SingleOrDefault(p => p.Name == "P2")).SetClrPropertyInfo(mockPropertyInfo2);
var mockPropertyInfo1 = new MockPropertyInfo(typeof(int), "P1");
entityTypeConfiguration.Key(mockPropertyInfo1);
entityTypeConfiguration.Property(new PropertyPath(mockPropertyInfo1)).ColumnOrder = 0;
(entityType.GetDeclaredPrimitiveProperties().SingleOrDefault(p => p.Name == "P1")).SetClrPropertyInfo(mockPropertyInfo1);
entityTypeConfiguration.Configure(entityType, new EdmModel(DataSpace.CSpace));
Assert.Equal(2, entityType.KeyProperties.Count);
Assert.Equal("P1", entityType.KeyProperties.First().Name);
}
示例4: Configure_should_throw_when_property_not_found
public void Configure_should_throw_when_property_not_found()
{
var entityType = new EntityType("E", "N", DataSpace.CSpace);
var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object));
var mockPropertyConfiguration = new Mock<PrimitivePropertyConfiguration>();
entityTypeConfiguration.Property(new PropertyPath(new MockPropertyInfo()), () => mockPropertyConfiguration.Object);
Assert.Equal(
Strings.PropertyNotFound(("P"), "E"),
Assert.Throws<InvalidOperationException>(
() => entityTypeConfiguration.Configure(entityType, new EdmModel(DataSpace.CSpace))).Message);
}
示例5: Configure_should_configure_properties
public void Configure_should_configure_properties()
{
var entityType = new EntityType("E", "N", DataSpace.CSpace);
var property = EdmProperty.CreatePrimitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
entityType.AddMember(property);
var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object));
var mockPropertyConfiguration = new Mock<PrimitivePropertyConfiguration>();
var mockPropertyInfo = new MockPropertyInfo();
property.SetClrPropertyInfo(mockPropertyInfo);
entityTypeConfiguration.Property(new PropertyPath(mockPropertyInfo), () => mockPropertyConfiguration.Object);
entityTypeConfiguration.Configure(entityType, new EdmModel(DataSpace.CSpace));
mockPropertyConfiguration.Verify(p => p.Configure(property));
}
示例6: Configure
internal override void Configure(
AssociationType associationType,
AssociationEndMember dependentEnd,
EntityTypeConfiguration entityTypeConfiguration)
{
DebugCheck.NotNull(associationType);
DebugCheck.NotNull(dependentEnd);
DebugCheck.NotNull(entityTypeConfiguration);
if (!_dependentProperties.Any())
{
return;
}
var dependentPropertyInfos = _dependentProperties.AsEnumerable();
if (!IsFullySpecified)
{
if (dependentEnd.GetEntityType().GetClrType() != entityTypeConfiguration.ClrType)
{
// This can only happen if the dependent end has a navigation property,
// as otherwise the column order has to be fully specified.
// Thus we can configure the constraint when we are configuring the navigation property on the dependent type
return;
}
var foreignKeys
= from p in _dependentProperties
select new
{
PropertyInfo = p,
entityTypeConfiguration.Property(new PropertyPath(p)).ColumnOrder
};
if ((_dependentProperties.Count > 1)
&& foreignKeys.Any(p => !p.ColumnOrder.HasValue))
{
var dependentKeys = dependentEnd.GetEntityType().KeyProperties;
if ((dependentKeys.Count == _dependentProperties.Count)
&& foreignKeys.All(fk => dependentKeys.Any(p => p.GetClrPropertyInfo().IsSameAs(fk.PropertyInfo))))
{
// The FK and PK sets are equal, we know the order
dependentPropertyInfos = dependentKeys.Select(p => p.GetClrPropertyInfo());
}
else
{
throw Error.ForeignKeyAttributeConvention_OrderRequired(entityTypeConfiguration.ClrType);
}
}
else
{
dependentPropertyInfos = foreignKeys.OrderBy(p => p.ColumnOrder).Select(p => p.PropertyInfo);
}
}
var dependentProperties = new List<EdmProperty>();
foreach (var dependentProperty in dependentPropertyInfos)
{
var property
= dependentEnd.GetEntityType()
.GetDeclaredPrimitiveProperty(dependentProperty);
if (property == null)
{
throw Error.ForeignKeyPropertyNotFound(
dependentProperty.Name, dependentEnd.GetEntityType().Name);
}
dependentProperties.Add(property);
}
var principalEnd = associationType.GetOtherEnd(dependentEnd);
var associationConstraint
= new ReferentialConstraint(
principalEnd,
dependentEnd,
principalEnd.GetEntityType().KeyProperties,
dependentProperties);
if (principalEnd.IsRequired())
{
associationConstraint.ToProperties.Each(p => p.Nullable = false);
}
associationType.Constraint = associationConstraint;
}