本文整理汇总了C#中INavigation.IsDependentToPrincipal方法的典型用法代码示例。如果您正苦于以下问题:C# INavigation.IsDependentToPrincipal方法的具体用法?C# INavigation.IsDependentToPrincipal怎么用?C# INavigation.IsDependentToPrincipal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类INavigation
的用法示例。
在下文中一共展示了INavigation.IsDependentToPrincipal方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NavigationReferenceChangedAction
private void NavigationReferenceChangedAction(InternalEntityEntry entry, INavigation navigation, object oldValue, object newValue)
{
var foreignKey = navigation.ForeignKey;
var dependentProperties = foreignKey.Properties;
var principalProperties = foreignKey.PrincipalKey.Properties;
if (navigation.IsDependentToPrincipal())
{
if (newValue != null)
{
SetForeignKeyValue(foreignKey, entry, entry.StateManager.GetOrCreateEntry(newValue));
}
else
{
SetNullForeignKey(entry, dependentProperties);
}
}
else
{
Debug.Assert(foreignKey.IsUnique);
if (newValue != null)
{
var dependentEntry = entry.StateManager.GetOrCreateEntry(newValue);
// Avoid eagerly setting FKs (which may be PKs) in un-tracked entities so as not to mess up
// Attach behavior that is based on key values.
if (dependentEntry.EntityState != EntityState.Detached)
{
SetForeignKeyValue(foreignKey, dependentEntry, entry);
}
}
if (oldValue != null)
{
ConditionallySetNullForeignKey(entry.StateManager.GetOrCreateEntry(oldValue), dependentProperties, entry, principalProperties);
}
}
if (oldValue != null)
{
ConditionallyClearInverse(entry, navigation, oldValue);
}
if (newValue != null)
{
SetInverse(entry, navigation, newValue);
}
}
示例2: NavigationMetadata
public NavigationMetadata(INavigation navigation, Type dbContextType)
{
Contract.Assert(navigation != null);
Contract.Assert(navigation.IsDependentToPrincipal());
AssociationPropertyName = navigation.Name;
DisplayPropertyName = AssociationPropertyName; //Needs further implementation
var otherEntityType = navigation.ForeignKey.ResolveOtherEntityType(navigation.DeclaringEntityType);
EntitySetName = ModelMetadata.GetEntitySetName(dbContextType, otherEntityType.ClrType);
TypeName = otherEntityType.ClrType.GetTypeInfo().FullName;
ShortTypeName = otherEntityType.ClrType.GetTypeInfo().Name;
PrimaryKeyNames = navigation.ForeignKey.PrincipalKey.Properties.Select(pk => pk.Name).ToArray();
ForeignKeyPropertyNames = navigation.ForeignKey.Properties
.Where(p => p.DeclaringEntityType == navigation.DeclaringEntityType)
.Select(p => p.Name)
.ToArray();
}
示例3: TryFindPrincipal
private static object TryFindPrincipal(IStateManager stateManager, INavigation navigation, object dependentEntity)
{
if (navigation.IsDependentToPrincipal())
{
return navigation.GetGetter().GetClrValue(dependentEntity);
}
// TODO: Perf
foreach (var principalEntry in stateManager.Entries.Where(
e => e.EntityState != EntityState.Detached
&& navigation.ForeignKey.PrincipalEntityType.IsAssignableFrom(e.EntityType)))
{
if (navigation.IsCollection())
{
if (navigation.GetCollectionAccessor().Contains(principalEntry.Entity, dependentEntity))
{
return principalEntry.Entity;
}
}
else if (navigation.GetGetter().GetClrValue(principalEntry.Entity) == dependentEntity)
{
return principalEntry.Entity;
}
}
return null;
}
示例4: DelayedFixup
private void DelayedFixup(InternalEntityEntry entry, INavigation navigation, InternalEntityEntry referencedEntry)
{
var navigationValue = entry[navigation];
if (navigationValue != null)
{
var setModified = referencedEntry.EntityState != EntityState.Unchanged;
if (!navigation.IsDependentToPrincipal())
{
if (navigation.IsCollection())
{
if (navigation.GetCollectionAccessor().Contains(entry.Entity, referencedEntry.Entity))
{
FixupToDependent(entry, referencedEntry, navigation.ForeignKey, setModified);
}
}
else if (referencedEntry.Entity == navigationValue)
{
FixupToDependent(entry, referencedEntry, navigation.ForeignKey, setModified);
}
}
else if (referencedEntry.Entity == navigationValue)
{
FixupToPrincipal(entry, referencedEntry, navigation.ForeignKey, setModified);
}
}
}
示例5: NavigationReferenceChanged
/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public virtual void NavigationReferenceChanged(InternalEntityEntry entry, INavigation navigation, object oldValue, object newValue)
{
if (_inFixup)
{
return;
}
var foreignKey = navigation.ForeignKey;
var stateManager = entry.StateManager;
var inverse = navigation.FindInverse();
var oldTargetEntry = oldValue == null ? null : stateManager.TryGetEntry(oldValue);
if (oldTargetEntry?.EntityState == EntityState.Detached)
{
oldTargetEntry = null;
}
var newTargetEntry = newValue == null ? null : stateManager.TryGetEntry(newValue);
if (newTargetEntry?.EntityState == EntityState.Detached)
{
newTargetEntry = null;
}
try
{
_inFixup = true;
if (navigation.IsDependentToPrincipal())
{
if (newValue != null)
{
if (newTargetEntry != null)
{
if (foreignKey.IsUnique)
{
// Navigation points to principal. Find the dependent that previously pointed to that principal and
// null out its FKs and navigation property. A.k.a. reference stealing.
// However, if the FK has already been changed or the reference is already set to point
// to something else, then don't change it.
var victimDependentEntry = stateManager.GetDependents(newTargetEntry, foreignKey).FirstOrDefault();
if (victimDependentEntry != null
&& victimDependentEntry != entry)
{
ConditionallyNullForeignKeyProperties(victimDependentEntry, newTargetEntry, foreignKey);
if (ReferenceEquals(victimDependentEntry[navigation], newTargetEntry.Entity))
{
SetNavigation(victimDependentEntry, navigation, null);
}
}
}
// Set the FK properties to reflect the change to the navigation.
SetForeignKeyProperties(entry, newTargetEntry, foreignKey, setModified: true);
}
}
else
{
// Null the FK properties to reflect that the navigation has been nulled out.
ConditionallyNullForeignKeyProperties(entry, oldTargetEntry, foreignKey);
}
if (inverse != null)
{
var collectionAccessor = inverse.IsCollection() ? inverse.GetCollectionAccessor() : null;
// Set the inverse reference or add the entity to the inverse collection
if (newTargetEntry != null)
{
SetReferenceOrAddToCollection(newTargetEntry, inverse, collectionAccessor, entry.Entity);
}
// Remove the entity from the old collection, or null the old inverse unless it was already
// changed to point to something else
if (oldTargetEntry != null)
{
if (collectionAccessor != null)
{
RemoveFromCollection(oldTargetEntry, inverse, collectionAccessor, entry.Entity);
}
else if (ReferenceEquals(oldTargetEntry[inverse], entry.Entity))
{
SetNavigation(oldTargetEntry, inverse, null);
}
}
}
}
else
{
Debug.Assert(foreignKey.IsUnique);
if (newTargetEntry != null)
{
// Navigation points to dependent and is 1:1. Find the principal that previously pointed to that
// dependent and null out its navigation property. A.k.a. reference stealing.
// However, if the reference is already set to point to something else, then don't change it.
//.........这里部分代码省略.........
示例6: IncludeCore
private IEntityType IncludeCore(
object entity,
INavigation navigation,
out IKeyValue primaryKeyValue,
out Func<ValueBuffer, IKeyValue> relatedKeyFactory)
{
var keyFactory
= _keyValueFactorySource
.GetKeyFactory(navigation.ForeignKey.PrincipalKey);
var targetEntityType = navigation.GetTargetType();
object boxedValueBuffer;
if (!_valueBuffers.TryGetValue(entity, out boxedValueBuffer))
{
var entry = _stateManager.TryGetEntry(entity);
Debug.Assert(entry != null);
primaryKeyValue
= navigation.IsDependentToPrincipal()
? entry.GetDependentKeyValue(navigation.ForeignKey)
: entry.GetPrimaryKeyValue();
}
else
{
primaryKeyValue
= navigation.IsDependentToPrincipal()
? keyFactory
.Create(
navigation.ForeignKey.Properties,
(ValueBuffer)boxedValueBuffer)
: keyFactory
.Create(
navigation.ForeignKey.PrincipalKey.Properties,
(ValueBuffer)boxedValueBuffer);
}
if (navigation.IsDependentToPrincipal())
{
relatedKeyFactory
= valueBuffer =>
keyFactory
.Create(
navigation.ForeignKey.PrincipalKey.Properties,
valueBuffer);
}
else
{
relatedKeyFactory
= valueBuffer =>
keyFactory
.Create(
navigation.ForeignKey.Properties,
valueBuffer);
}
return targetEntityType;
}
示例7: SetInverse
private void SetInverse(InternalEntityEntry entry, INavigation navigation, object entity)
{
var inverse = navigation.FindInverse();
if (inverse != null)
{
var inverseEntry = entry.StateManager.GetOrCreateEntry(entity);
if (inverse.IsCollection())
{
var collectionAccessor = inverse.GetCollectionAccessor();
if (!collectionAccessor.Contains(entity, entry.Entity))
{
collectionAccessor.Add(entity, entry.Entity);
}
}
else
{
var oldEntity = inverse.GetGetter().GetClrValue(entity);
if (oldEntity != null
&& oldEntity != entry.Entity)
{
var oldEntry = entry.StateManager.GetOrCreateEntry(oldEntity);
if (navigation.IsDependentToPrincipal())
{
Unfixup(navigation, inverseEntry, oldEntry);
SetNullForeignKey(oldEntry, navigation.ForeignKey.Properties);
}
else
{
Unfixup(navigation, oldEntry, inverseEntry);
}
}
inverse.GetSetter().SetClrValue(entity, entry.Entity);
}
inverseEntry.RelationshipsSnapshot.TakeSnapshot(inverse);
}
}
示例8: Unfixup
private void Unfixup(INavigation navigation, InternalEntityEntry oldPrincipalEntry, InternalEntityEntry dependentEntry)
{
if (navigation.IsDependentToPrincipal())
{
navigation.GetSetter().SetClrValue(dependentEntry.Entity, null);
dependentEntry.RelationshipsSnapshot.TakeSnapshot(navigation);
}
else
{
if (navigation.IsCollection())
{
var collectionAccessor = navigation.GetCollectionAccessor();
if (collectionAccessor.Contains(oldPrincipalEntry.Entity, dependentEntry.Entity))
{
collectionAccessor.Remove(oldPrincipalEntry.Entity, dependentEntry.Entity);
}
}
else
{
navigation.GetSetter().SetClrValue(oldPrincipalEntry.Entity, null);
}
}
}