本文整理汇总了C#中System.Data.Entity.Core.Metadata.Edm.AssociationEndMember.GetEntityType方法的典型用法代码示例。如果您正苦于以下问题:C# AssociationEndMember.GetEntityType方法的具体用法?C# AssociationEndMember.GetEntityType怎么用?C# AssociationEndMember.GetEntityType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.Entity.Core.Metadata.Edm.AssociationEndMember
的用法示例。
在下文中一共展示了AssociationEndMember.GetEntityType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MatchDependentKeyProperty
/// <inheritdoc/>
protected override bool MatchDependentKeyProperty(
AssociationType associationType,
AssociationEndMember dependentAssociationEnd,
EdmProperty dependentProperty,
EntityType principalEntityType,
EdmProperty principalKeyProperty)
{
Check.NotNull(associationType, "associationType");
Check.NotNull(dependentAssociationEnd, "dependentAssociationEnd");
Check.NotNull(dependentProperty, "dependentProperty");
Check.NotNull(principalEntityType, "principalEntityType");
Check.NotNull(principalKeyProperty, "principalKeyProperty");
var otherEnd = associationType.GetOtherEnd(dependentAssociationEnd);
var navigationProperty
= dependentAssociationEnd.GetEntityType().NavigationProperties
.SingleOrDefault(n => n.ResultEnd == otherEnd);
if (navigationProperty == null)
{
return false;
}
return string.Equals(
dependentProperty.Name, navigationProperty.Name + principalKeyProperty.Name,
StringComparison.OrdinalIgnoreCase);
}
开发者ID:hallco978,项目名称:entityframework,代码行数:29,代码来源:NavigationPropertyNameForeignKeyDiscoveryConvention.cs
示例2: TryCreateReferentialConstraint
private static ReferentialConstraint TryCreateReferentialConstraint(
IList<RelationshipDetailsRow> relationshipDetailsRows,
AssociationEndMember pkEnd,
AssociationEndMember fkEnd,
IList<EdmSchemaError> errors)
{
var fromProperties = new EdmProperty[relationshipDetailsRows.Count];
var toProperties = new EdmProperty[relationshipDetailsRows.Count];
var pkEntityType = pkEnd.GetEntityType();
var fkEntityType = fkEnd.GetEntityType();
for (var index = 0; index < relationshipDetailsRows.Count; index++)
{
EdmProperty property;
var row = relationshipDetailsRows[index];
if (!pkEntityType.Properties.TryGetValue(row.PKColumn, false, out property))
{
errors.Add(
new EdmSchemaError(
string.Format(
CultureInfo.InvariantCulture,
Resources_VersioningFacade.AssociationMissingKeyColumn,
pkEntityType.Name,
fkEntityType.Name,
pkEntityType.Name + "." + row.PKColumn),
(int)ModelBuilderErrorCode.AssociationMissingKeyColumn,
EdmSchemaErrorSeverity.Warning));
return null;
}
fromProperties[index] = property;
if (!fkEntityType.Properties.TryGetValue(row.FKColumn, false, out property))
{
errors.Add(
new EdmSchemaError(
string.Format(
CultureInfo.InvariantCulture,
Resources_VersioningFacade.AssociationMissingKeyColumn,
pkEntityType.Name,
fkEntityType.Name,
pkEntityType.Name + "." + row.FKColumn),
(int)ModelBuilderErrorCode.AssociationMissingKeyColumn,
EdmSchemaErrorSeverity.Warning));
return null;
}
toProperties[index] = property;
}
return new ReferentialConstraint(pkEnd, fkEnd, fromProperties, toProperties);
}
示例3: GetFkName
// <summary>
// 1. If there is a NavigationProperty on the dependent end, then the FK name will be: [NavProp Name]_[Property Name]
// 2. If there isn't a NavigationProperty, then we will use the [Association Name]_[EndName]_[Property Name]
// </summary>
internal static string GetFkName(AssociationType association, AssociationEndMember endWithNavProp, string keyPropertyName)
{
var fkName = String.Empty;
// We attempt to find a navigation property that uses the same association and points to the other end. That last
// part is important with self-associations.
var principalEnd = association.GetOtherEnd(endWithNavProp);
var navigationProperty = endWithNavProp
.GetEntityType()
.NavigationProperties
.Where(np => (np.RelationshipType == association && np.ToEndMember == principalEnd)).FirstOrDefault();
if (navigationProperty != null)
{
// First attempt to find the NavigationProperty that points to the principal end
fkName = String.Format(CultureInfo.CurrentCulture, "{0}_{1}", navigationProperty.Name, keyPropertyName);
}
else if (association != null)
{
// If there isn't a NavigationProperty defined, then we will use the Association Name
fkName = String.Format(CultureInfo.CurrentCulture, "{0}_{1}_{2}", association.Name, endWithNavProp.Name, keyPropertyName);
}
Debug.Assert(!String.IsNullOrEmpty(fkName), "Foreign key name could not be determined for the association " + association.Name);
return fkName;
}
示例4: 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 dependentPropertInfos = _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.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
dependentPropertInfos = dependentKeys.Select(p => p.GetClrPropertyInfo());
}
else
{
throw Error.ForeignKeyAttributeConvention_OrderRequired(entityTypeConfiguration.ClrType);
}
}
else
{
dependentPropertInfos = foreignKeys.OrderBy(p => p.ColumnOrder).Select(p => p.PropertyInfo);
}
}
var dependentProperties = new List<EdmProperty>();
foreach (var dependentProperty in dependentPropertInfos)
{
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;
}
示例5: CheckEntitySetAgainstEndMember
private static bool CheckEntitySetAgainstEndMember(EntitySet entitySet, AssociationEndMember endMember)
{
return (entitySet == null && endMember == null)
|| (entitySet != null && endMember != null && entitySet.ElementType == endMember.GetEntityType());
}