本文整理汇总了C#中INavigation.GetCollectionAccessor方法的典型用法代码示例。如果您正苦于以下问题:C# INavigation.GetCollectionAccessor方法的具体用法?C# INavigation.GetCollectionAccessor怎么用?C# INavigation.GetCollectionAccessor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类INavigation
的用法示例。
在下文中一共展示了INavigation.GetCollectionAccessor方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: AsINotifyCollectionChanged
private static INotifyCollectionChanged AsINotifyCollectionChanged(
InternalEntityEntry entry,
INavigation navigation,
IEntityType entityType,
ChangeTrackingStrategy changeTrackingStrategy)
{
var notifyingCollection = navigation.GetCollectionAccessor().GetOrCreate(entry.Entity) as INotifyCollectionChanged;
if (notifyingCollection == null)
{
throw new InvalidOperationException(
CoreStrings.NonNotifyingCollection(navigation.Name, entityType.DisplayName(), changeTrackingStrategy));
}
return notifyingCollection;
}
示例3: AddRangeToCollection
private void AddRangeToCollection(object entity, INavigation navigation, IEnumerable<object> values, bool tracking)
{
navigation.GetCollectionAccessor().AddRange(entity, values);
if (tracking)
{
_stateManager.TryGetEntry(entity)?.AddRangeToCollectionSnapshot(navigation, values);
}
}
示例4: AddToCollection
private void AddToCollection(object entity, INavigation navigation, object value, bool tracking)
{
navigation.GetCollectionAccessor().Add(entity, value);
if (tracking)
{
_stateManager.TryGetEntry(entity)?.AddToCollectionSnapshot(navigation, value);
}
}
示例5: 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);
}
}
}
示例6: NavigationCollectionChanged
/// <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 NavigationCollectionChanged(
InternalEntityEntry entry,
INavigation navigation,
IEnumerable<object> added,
IEnumerable<object> removed)
{
if (_inFixup)
{
return;
}
var foreignKey = navigation.ForeignKey;
var stateManager = entry.StateManager;
var inverse = navigation.FindInverse();
var collectionAccessor = navigation.GetCollectionAccessor();
foreach (var oldValue in removed)
{
var oldTargetEntry = stateManager.TryGetEntry(oldValue);
if (oldTargetEntry != null
&& oldTargetEntry.EntityState != EntityState.Detached)
{
try
{
_inFixup = true;
// Null FKs and navigations of dependents that have been removed, unless they
// have already been changed.
ConditionallyNullForeignKeyProperties(oldTargetEntry, entry, foreignKey);
if (inverse != null
&& ReferenceEquals(oldTargetEntry[inverse], entry.Entity))
{
SetNavigation(oldTargetEntry, inverse, null);
}
entry.RemoveFromCollectionSnapshot(navigation, oldValue);
}
finally
{
_inFixup = false;
}
}
}
foreach (var newValue in added)
{
var newTargetEntry = stateManager.GetOrCreateEntry(newValue);
if (newTargetEntry.EntityState != EntityState.Detached)
{
try
{
_inFixup = true;
// For a dependent added to the collection, remove it from the collection of
// the principal entity that it was previously part of
var oldPrincipalEntry = stateManager.GetPrincipal(newTargetEntry, foreignKey);
if (oldPrincipalEntry != null)
{
RemoveFromCollection(oldPrincipalEntry, navigation, collectionAccessor, newValue);
}
// Set the FK properties on added dependents to match this principal
SetForeignKeyProperties(newTargetEntry, entry, foreignKey, setModified: true);
// Set the inverse navigation to point to this principal
SetNavigation(newTargetEntry, inverse, entry.Entity);
}
finally
{
_inFixup = false;
}
}
else
{
stateManager.RecordReferencedUntrackedEntity(newValue, navigation, entry);
_attacher.AttachGraph(newTargetEntry, EntityState.Added);
}
entry.AddToCollectionSnapshot(navigation, newValue);
}
}
示例7: 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);
}
}
}