本文整理汇总了C#中INavigation.IsCollection方法的典型用法代码示例。如果您正苦于以下问题:C# INavigation.IsCollection方法的具体用法?C# INavigation.IsCollection怎么用?C# INavigation.IsCollection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类INavigation
的用法示例。
在下文中一共展示了INavigation.IsCollection方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryFindPrincipal
private object TryFindPrincipal(StateManager stateManager, INavigation navigation, object dependentEntity)
{
if (navigation.PointsToPrincipal)
{
return _getterSource.GetAccessor(navigation).GetClrValue(dependentEntity);
}
// TODO: Perf
foreach (var principalEntry in stateManager.StateEntries
.Where(e => e.EntityType == navigation.ForeignKey.ReferencedEntityType))
{
if (navigation.IsCollection())
{
if (_collectionAccessorSource.GetAccessor(navigation).Contains(principalEntry.Entity, dependentEntity))
{
return principalEntry.Entity;
}
}
else if (_getterSource.GetAccessor(navigation).GetClrValue(principalEntry.Entity) == dependentEntity)
{
return principalEntry.Entity;
}
}
return null;
}
示例2: GetEdmMultiplicity
private static EdmMultiplicity GetEdmMultiplicity(
INavigation navi)
{
if (navi.IsCollection())
{
return EdmMultiplicity.Many;
}
if (navi.ForeignKey.IsRequired)
{
return EdmMultiplicity.One;
}
return EdmMultiplicity.ZeroOrOne;
}
示例3: DetectNavigationChange
private void DetectNavigationChange(InternalEntityEntry entry, INavigation navigation, Sidecar snapshot)
{
var snapshotValue = snapshot[navigation];
var currentValue = entry[navigation];
var stateManager = entry.StateManager;
var added = new HashSet<object>(ReferenceEqualityComparer.Instance);
if (navigation.IsCollection())
{
var snapshotCollection = (IEnumerable)snapshotValue;
var currentCollection = (IEnumerable)currentValue;
var removed = new HashSet<object>(ReferenceEqualityComparer.Instance);
if (snapshotCollection != null)
{
foreach (var entity in snapshotCollection)
{
removed.Add(entity);
}
}
if (currentCollection != null)
{
foreach (var entity in currentCollection)
{
if (!removed.Remove(entity))
{
added.Add(entity);
}
}
}
if (added.Any()
|| removed.Any())
{
stateManager.Notify.NavigationCollectionChanged(entry, navigation, added, removed);
snapshot.TakeSnapshot(navigation);
}
}
else if (!ReferenceEquals(currentValue, snapshotValue))
{
stateManager.Notify.NavigationReferenceChanged(entry, navigation, snapshotValue, currentValue);
if (currentValue != null)
{
added.Add(currentValue);
}
snapshot.TakeSnapshot(navigation);
}
foreach (var addedEntity in added)
{
var addedEntry = stateManager.GetOrCreateEntry(addedEntity);
if (addedEntry.EntityState == EntityState.Detached)
{
_attacher.AttachGraph(addedEntry, EntityState.Added);
}
}
}
示例4: Unfixup
private void Unfixup(INavigation navigation, InternalEntityEntry oldPrincipalEntry, InternalEntityEntry dependentEntry)
{
if (navigation.PointsToPrincipal())
{
_setterSource.GetAccessor(navigation).SetClrValue(dependentEntry.Entity, null);
dependentEntry.RelationshipsSnapshot.TakeSnapshot(navigation);
}
else
{
if (navigation.IsCollection())
{
var collectionAccessor = _collectionAccessorSource.GetAccessor(navigation);
if (collectionAccessor.Contains(oldPrincipalEntry.Entity, dependentEntry.Entity))
{
collectionAccessor.Remove(oldPrincipalEntry.Entity, dependentEntry.Entity);
}
}
else
{
_setterSource.GetAccessor(navigation).SetClrValue(oldPrincipalEntry.Entity, null);
}
}
}
示例5: DetectNavigationChange
private void DetectNavigationChange(InternalEntityEntry entry, INavigation navigation)
{
var snapshotValue = entry.GetRelationshipSnapshotValue(navigation);
var currentValue = entry[navigation];
var stateManager = entry.StateManager;
if (navigation.IsCollection())
{
var snapshotCollection = (IEnumerable)snapshotValue;
var currentCollection = (IEnumerable)currentValue;
var removed = new HashSet<object>(ReferenceEqualityComparer.Instance);
if (snapshotCollection != null)
{
foreach (var entity in snapshotCollection)
{
removed.Add(entity);
}
}
var added = new HashSet<object>(ReferenceEqualityComparer.Instance);
if (currentCollection != null)
{
foreach (var entity in currentCollection)
{
if (!removed.Remove(entity))
{
added.Add(entity);
}
}
}
if (added.Any()
|| removed.Any())
{
stateManager.Notify.NavigationCollectionChanged(entry, navigation, added, removed);
}
}
else if (!ReferenceEquals(currentValue, snapshotValue))
{
stateManager.Notify.NavigationReferenceChanged(entry, navigation, snapshotValue, currentValue);
}
}
示例6: NavigationCollectionChangedAction
private void NavigationCollectionChangedAction(
StateEntry entry, INavigation navigation, IEnumerable<object> added, IEnumerable<object> removed)
{
Contract.Assert(navigation.IsCollection());
var stateManager = _configuration.StateManager;
var dependentProperties = navigation.ForeignKey.Properties;
var principalValues = navigation.ForeignKey.ReferencedProperties.Select(p => entry[p]).ToArray();
// TODO: What if the entity is not yet being tracked?
foreach (var entity in removed)
{
ConditionallySetNullForeignKey(stateManager.GetOrCreateEntry(entity), dependentProperties, principalValues);
ConditionallyClearInverse(entry, navigation, entity);
}
foreach (var entity in added)
{
SetForeignKeyValue(stateManager.GetOrCreateEntry(entity), dependentProperties, principalValues);
SetInverse(entry, navigation, entity);
}
}
示例7: 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;
}
示例8: DetectNavigationChange
private bool DetectNavigationChange(StateEntry entry, INavigation navigation)
{
var snapshotValue = entry.RelationshipsSnapshot[navigation];
var currentValue = entry[navigation];
if (navigation.IsCollection())
{
var snapshotCollection = (IEnumerable)snapshotValue;
var currentCollection = (IEnumerable)currentValue;
var added = new HashSet<object>(ReferenceEqualityComparer.Instance);
var removed = new HashSet<object>(ReferenceEqualityComparer.Instance);
foreach (var entity in snapshotCollection)
{
removed.Add(entity);
}
foreach (var entity in currentCollection)
{
if (!removed.Remove(entity))
{
added.Add(entity);
}
}
if (added.Any()
|| removed.Any())
{
_notifier.NavigationCollectionChanged(entry, navigation, added, removed);
return true;
}
}
else if (!ReferenceEquals(currentValue, snapshotValue))
{
_notifier.NavigationReferenceChanged(entry, navigation, snapshotValue, currentValue);
return true;
}
return false;
}
示例9: 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);
}
}
}