本文整理汇总了C#中INavigation.GetTargetType方法的典型用法代码示例。如果您正苦于以下问题:C# INavigation.GetTargetType方法的具体用法?C# INavigation.GetTargetType怎么用?C# INavigation.GetTargetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类INavigation
的用法示例。
在下文中一共展示了INavigation.GetTargetType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddNavigationProperties
private static void AddNavigationProperties(
IModel efModel, INavigation navi,
EdmModel model, IDictionary<IAnnotatable, IEdmElement> elementMap)
{
if (!navi.PointsToPrincipal())
{
return;
}
var naviPair = new INavigation[] { navi, navi.FindInverse() };
var navPropertyInfos = new EdmNavigationPropertyInfo[2];
for (var i = 0; i < 2; i++)
{
var efEnd = naviPair[i];
if (efEnd == null) continue;
var efEntityType = efEnd.DeclaringEntityType;
if (!elementMap.ContainsKey(efEntityType))
{
continue;
}
var entityType = elementMap[efEntityType] as IEdmEntityType;
var efTargetEntityType = naviPair[i].GetTargetType();
if (!elementMap.ContainsKey(efTargetEntityType))
{
continue;
}
var targetEntityType = elementMap[
efTargetEntityType] as IEdmEntityType;
navPropertyInfos[i] = new EdmNavigationPropertyInfo()
{
ContainsTarget = false,
Name = naviPair[i].Name,
// TODO GitHubIssue#57: Complete EF7 to EDM model mapping
//OnDelete = efEnd.DeleteBehavior == OperationAction.Cascade
// ? EdmOnDeleteAction.Cascade : EdmOnDeleteAction.None,
OnDelete = EdmOnDeleteAction.None,
Target = targetEntityType,
TargetMultiplicity = ModelProducer.GetEdmMultiplicity(
naviPair[i]),
};
var foreignKey = naviPair[i].ForeignKey;
if (foreignKey != null && naviPair[i].PointsToPrincipal())
{
navPropertyInfos[i].DependentProperties = foreignKey.Properties
.Select(p => entityType.FindProperty(p.Name) as IEdmStructuralProperty);
navPropertyInfos[i].PrincipalProperties = foreignKey.PrincipalKey.Properties
.Select(p => targetEntityType.FindProperty(p.Name) as IEdmStructuralProperty);
}
}
if (navPropertyInfos[0] == null && navPropertyInfos[1] != null)
{
var efEntityType = navi.GetTargetType();
var entityType = elementMap[efEntityType] as EdmEntityType;
if (entityType.FindProperty(navPropertyInfos[1].Name) == null)
{
entityType.AddUnidirectionalNavigation(navPropertyInfos[1]);
}
}
if (navPropertyInfos[0] != null && navPropertyInfos[1] == null)
{
var efEntityType = navi.DeclaringEntityType;
var entityType = elementMap[efEntityType] as EdmEntityType;
if (entityType.FindProperty(navPropertyInfos[0].Name) == null)
{
entityType.AddUnidirectionalNavigation(navPropertyInfos[0]);
}
}
if (navPropertyInfos[0] != null && navPropertyInfos[1] != null)
{
var efEntityType = navi.DeclaringEntityType;
var entityType = elementMap[efEntityType] as EdmEntityType;
if (entityType.FindProperty(navPropertyInfos[0].Name) == null)
{
entityType.AddBidirectionalNavigation(
navPropertyInfos[0], navPropertyInfos[1]);
}
}
}
示例2: IncludeCore
private IEntityType IncludeCore(
object entity,
INavigation navigation,
out EntityKey primaryKey,
out List<BufferedEntity> bufferedEntities,
out Func<IValueReader, EntityKey> relatedKeyFactory)
{
var primaryKeyFactory
= _entityKeyFactorySource
.GetKeyFactory(navigation.ForeignKey.PrincipalKey.Properties);
var foreignKeyFactory
= _entityKeyFactorySource
.GetKeyFactory(navigation.ForeignKey.Properties);
var targetEntityType = navigation.GetTargetType();
if (!_byEntityInstance.TryGetValue(entity, out bufferedEntities))
{
_byEntityInstance.Add(entity, bufferedEntities = new List<BufferedEntity> { null });
var entry = _stateManager.TryGetEntry(entity);
Debug.Assert(entry != null);
primaryKey
= navigation.PointsToPrincipal
? entry.GetDependentKeySnapshot(navigation.ForeignKey)
: entry.GetPrimaryKeyValue();
}
else
{
// if entity is already in state manager it can't be added to the buffer. 'null' value was added to signify that
// this means relevant key should be acquired from state manager rather than buffered reader
if (bufferedEntities[0] == null)
{
var entry = _stateManager.TryGetEntry(entity);
Debug.Assert(entry != null);
primaryKey
= navigation.PointsToPrincipal
? entry.GetDependentKeySnapshot(navigation.ForeignKey)
: entry.GetPrimaryKeyValue();
}
else
{
primaryKey
= navigation.PointsToPrincipal
? foreignKeyFactory
.Create(
targetEntityType,
navigation.ForeignKey.Properties,
bufferedEntities[0].ValueReader)
: primaryKeyFactory
.Create(
navigation.EntityType,
navigation.ForeignKey.PrincipalKey.Properties,
bufferedEntities[0].ValueReader);
}
}
if (navigation.PointsToPrincipal)
{
relatedKeyFactory
= valueReader =>
primaryKeyFactory
.Create(
targetEntityType,
navigation.ForeignKey.PrincipalKey.Properties,
valueReader);
}
else
{
relatedKeyFactory
= valueReader =>
foreignKeyFactory
.Create(
navigation.EntityType,
navigation.ForeignKey.Properties,
valueReader);
}
return targetEntityType;
}
示例3: IncludeCore
private IEntityType IncludeCore(
object entity,
INavigation navigation,
out EntityKey primaryKey,
out Func<ValueBuffer, EntityKey> relatedKeyFactory)
{
var primaryKeyFactory
= _entityKeyFactorySource
.GetKeyFactory(navigation.ForeignKey.PrincipalKey.Properties);
var foreignKeyFactory
= _entityKeyFactorySource
.GetKeyFactory(navigation.ForeignKey.Properties);
var targetEntityType = navigation.GetTargetType();
object boxedValueBuffer;
if (!_valueBuffers.TryGetValue(entity, out boxedValueBuffer))
{
var entry = _stateManager.TryGetEntry(entity);
Debug.Assert(entry != null);
primaryKey
= navigation.PointsToPrincipal()
? entry.GetDependentKeySnapshot(navigation.ForeignKey)
: entry.GetPrimaryKeyValue();
}
else
{
primaryKey
= navigation.PointsToPrincipal()
? foreignKeyFactory
.Create(
targetEntityType.RootType(),
navigation.ForeignKey.Properties,
(ValueBuffer)boxedValueBuffer)
: primaryKeyFactory
.Create(
navigation.DeclaringEntityType.RootType(),
navigation.ForeignKey.PrincipalKey.Properties,
(ValueBuffer)boxedValueBuffer);
}
if (navigation.PointsToPrincipal())
{
relatedKeyFactory
= valueBuffer =>
primaryKeyFactory
.Create(
targetEntityType.RootType(),
navigation.ForeignKey.PrincipalKey.Properties,
valueBuffer);
}
else
{
relatedKeyFactory
= valueBuffer =>
foreignKeyFactory
.Create(
navigation.DeclaringEntityType.RootType(),
navigation.ForeignKey.Properties,
valueBuffer);
}
return targetEntityType;
}
示例4: 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;
}