本文整理汇总了C#中StructuralType类的典型用法代码示例。如果您正苦于以下问题:C# StructuralType类的具体用法?C# StructuralType怎么用?C# StructuralType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StructuralType类属于命名空间,在下文中一共展示了StructuralType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryGetMember
// <summary>
// Given the type in the target space and the member name in the source space,
// get the corresponding member in the target space
// For e.g. consider a Conceptual Type 'Abc' with a member 'Def' and a CLR type
// 'XAbc' with a member 'YDef'. If one has a reference to Abc one can
// invoke GetMember(Abc,"YDef") to retrieve the member metadata for Def
// </summary>
// <param name="type"> The type in the target perspective </param>
// <param name="memberName"> the name of the member in the source perspective </param>
// <param name="ignoreCase"> Whether to do case-sensitive member look up or not </param>
// <param name="outMember"> returns the member in target space, if a match is found </param>
internal virtual bool TryGetMember(StructuralType type, String memberName, bool ignoreCase, out EdmMember outMember)
{
DebugCheck.NotNull(type);
Check.NotEmpty(memberName, "memberName");
outMember = null;
return type.Members.TryGetValue(memberName, ignoreCase, out outMember);
}
示例2: TryGetMember
/// <summary>
/// Given the type in the target space and the member name in the source space,
/// get the corresponding member in the target space
/// For e.g. consider a Conceptual Type 'Foo' with a member 'Bar' and a CLR type
/// 'XFoo' with a member 'YBar'. If one has a reference to Foo one can
/// invoke GetMember(Foo,"YBar") to retrieve the member metadata for bar
/// </summary>
/// <param name="type">The type in the target perspective</param>
/// <param name="memberName">the name of the member in the source perspective</param>
/// <param name="ignoreCase">Whether to do case-sensitive member look up or not</param>
/// <param name="outMember">returns the member in target space, if a match is found</param>
internal virtual bool TryGetMember(StructuralType type, String memberName, bool ignoreCase, out EdmMember outMember)
{
EntityUtil.CheckArgumentNull(type, "type");
EntityUtil.CheckStringArgument(memberName, "memberName");
outMember = null;
return type.Members.TryGetValue(memberName, ignoreCase, out outMember);
}
示例3: GetRename
private FunctionImportReturnTypeStructuralTypeColumn GetRename(StructuralType typeForRename)
{
var ofTypecolumn = _columnListForType.FirstOrDefault(t => t.Type == typeForRename);
if (null != ofTypecolumn)
{
return ofTypecolumn;
}
// if there are duplicate istypeof mapping defined rename for the same column, the last one wins
var isOfTypeColumn = _columnListForIsTypeOfType.Where(t => t.Type == typeForRename).LastOrDefault();
if (null != isOfTypeColumn)
{
return isOfTypeColumn;
}
else
{
// find out all the tyes that is isparent type of this lookup type
var nodesInBaseHierachy =
_columnListForIsTypeOfType.Where(t => t.Type.IsAssignableFrom(typeForRename));
if (nodesInBaseHierachy.Count() == 0)
{
// non of its parent is renamed, so it will take the default one
return new FunctionImportReturnTypeStructuralTypeColumn(_defaultMemberName, typeForRename, false, null);
}
else
{
// we will guarantee that there will be some mapping for us on this column
// find out which one is lowest on the link
return GetLowestParentInHierachy(nodesInBaseHierachy);
}
}
}
开发者ID:christiandpena,项目名称:entityframework,代码行数:34,代码来源:FunctionImportReturnTypeStructuralTypeColumnRenameMapping.ReturnTypeRenameMapping.cs
示例4: LinqToEntitiesTypeDescriptor
/// <summary>
/// Constructor taking a metadata context, an structural type, and a parent custom type descriptor
/// </summary>
/// <param name="typeDescriptionContext">The <see cref="LinqToEntitiesTypeDescriptionContext"/> context.</param>
/// <param name="edmType">The <see cref="StructuralType"/> type (can be an entity or complex type).</param>
/// <param name="parent">The parent custom type descriptor.</param>
public LinqToEntitiesTypeDescriptor(LinqToEntitiesTypeDescriptionContext typeDescriptionContext, StructuralType edmType, ICustomTypeDescriptor parent)
: base(parent)
{
_typeDescriptionContext = typeDescriptionContext;
_edmType = edmType;
EdmMember[] timestampMembers = _edmType.Members.Where(p => ObjectContextUtilities.IsConcurrencyTimestamp(p)).ToArray();
if (timestampMembers.Length == 1)
{
_timestampMember = timestampMembers[0];
}
if (edmType.BuiltInTypeKind == BuiltInTypeKind.EntityType)
{
// if any FK member of any association is also part of the primary key, then the key cannot be marked
// Editable(false)
EntityType entityType = (EntityType)edmType;
_foreignKeyMembers = new HashSet<EdmMember>(entityType.NavigationProperties.SelectMany(p => p.GetDependentProperties()));
foreach (EdmProperty foreignKeyMember in _foreignKeyMembers)
{
if (entityType.KeyMembers.Contains(foreignKeyMember))
{
_keyIsEditable = true;
break;
}
}
}
}
示例5: ClientPropertyNameToServer
public override string ClientPropertyNameToServer(string serverName, StructuralType parentType) {
if (parentType.Namespace == "Model.Edmunds") {
return serverName.Substring(0, 1).ToLower() + serverName.Substring(1);
} else {
return base.ClientPropertyNameToServer(serverName, parentType);
}
}
示例6: FunctionImportReturnTypeStructuralTypeColumn
internal FunctionImportReturnTypeStructuralTypeColumn(string columnName, StructuralType type, bool isTypeOf, LineInfo lineInfo)
{
ColumnName = columnName;
IsTypeOf = isTypeOf;
Type = type;
LineInfo = lineInfo;
}
示例7: ClientPropertyNameToServer
public override string ClientPropertyNameToServer(string clientPropertyName, StructuralType parentType) {
String serverPropertyName;
if (_clientServerPropNameMap.TryGetValue(clientPropertyName, out serverPropertyName)) {
serverPropertyName = clientPropertyName;
}
return serverPropertyName;
}
示例8: ServerPropertyNameToClient
public override String ServerPropertyNameToClient(String serverPropertyName, StructuralType parentType) {
if (serverPropertyName.IndexOf("_", StringComparison.InvariantCulture) != -1) {
var clientPropertyName = serverPropertyName.Replace("_", "");
_clientServerPropNameMap[clientPropertyName] = serverPropertyName;
return clientPropertyName;
} else {
return base.ServerPropertyNameToClient(serverPropertyName, parentType);
}
}
示例9: TryCreateStructuralType
private bool TryCreateStructuralType(Type type, StructuralType cspaceType, out EdmType newOSpaceType)
{
DebugCheck.NotNull(type);
DebugCheck.NotNull(cspaceType);
var referenceResolutionListForCurrentType = new List<Action>();
newOSpaceType = null;
StructuralType ospaceType;
if (Helper.IsEntityType(cspaceType))
{
ospaceType = new ClrEntityType(type, cspaceType.NamespaceName, cspaceType.Name);
}
else
{
Debug.Assert(Helper.IsComplexType(cspaceType), "Invalid type attribute encountered");
ospaceType = new ClrComplexType(type, cspaceType.NamespaceName, cspaceType.Name);
}
if (cspaceType.BaseType != null)
{
if (TypesMatchByConvention(type.BaseType(), cspaceType.BaseType))
{
TrackClosure(type.BaseType());
referenceResolutionListForCurrentType.Add(
() => ospaceType.BaseType = ResolveBaseType((StructuralType)cspaceType.BaseType, type));
}
else
{
var message = Strings.Validator_OSpace_Convention_BaseTypeIncompatible(
type.BaseType().FullName, type.FullName, cspaceType.BaseType.FullName);
LogLoadMessage(message, cspaceType);
return false;
}
}
// Load the properties for this type
if (!TryCreateMembers(type, cspaceType, ospaceType, referenceResolutionListForCurrentType))
{
return false;
}
// Add this to the known type map so we won't try to load it again
LoadedTypes.Add(type.FullName, ospaceType);
// we only add the referenceResolution to the list unless we structrually matched this type
foreach (var referenceResolution in referenceResolutionListForCurrentType)
{
ReferenceResolutions.Add(referenceResolution);
}
newOSpaceType = ospaceType;
return true;
}
示例10: Map
internal Type Map(StructuralType objectSpaceType)
{
Type type;
if (!lookup.TryGetValue(objectSpaceType.FullName, out type))
{
// For some reason the type wasn't in the typeLookup we built when we
// constructed this class. If we encountered any errors building that lookup
// they will be in the typeLoadErrors collection we pass to the exception.
throw new UnknownTypeException(objectSpaceType.FullName, typeLoadErrors);
}
return type;
}
示例11: CreateFunctionImportStructuralTypeColumnMap
/// <summary>
/// Creates a column map for the given reader and function mapping.
/// </summary>
internal virtual CollectionColumnMap CreateFunctionImportStructuralTypeColumnMap(
DbDataReader storeDataReader, FunctionImportMappingNonComposable mapping, int resultSetIndex, EntitySet entitySet,
StructuralType baseStructuralType)
{
var resultMapping = mapping.GetResultMapping(resultSetIndex);
Debug.Assert(resultMapping != null);
if (resultMapping.NormalizedEntityTypeMappings.Count == 0) // no explicit mapping; use default non-polymorphic reader
{
// if there is no mapping, create default mapping to root entity type or complex type
Debug.Assert(!baseStructuralType.Abstract, "mapping loader must verify abstract types have explicit mapping");
return CreateColumnMapFromReaderAndType(
storeDataReader, baseStructuralType, entitySet, resultMapping.ReturnTypeColumnsRenameMapping);
}
// the section below deals with the polymorphic entity type mapping for return type
var baseEntityType = baseStructuralType as EntityType;
Debug.Assert(null != baseEntityType, "We should have entity type here");
// Generate column maps for all discriminators
var discriminatorColumns = CreateDiscriminatorColumnMaps(storeDataReader, mapping, resultSetIndex);
// Generate default maps for all mapped entity types
var mappedEntityTypes = new HashSet<EntityType>(resultMapping.MappedEntityTypes);
mappedEntityTypes.Add(baseEntityType); // make sure the base type is represented
var typeChoices = new Dictionary<EntityType, TypedColumnMap>(mappedEntityTypes.Count);
ColumnMap[] baseTypeColumnMaps = null;
foreach (var entityType in mappedEntityTypes)
{
var propertyColumnMaps = GetColumnMapsForType(storeDataReader, entityType, resultMapping.ReturnTypeColumnsRenameMapping);
var entityColumnMap = CreateEntityTypeElementColumnMap(
storeDataReader, entityType, entitySet, propertyColumnMaps, resultMapping.ReturnTypeColumnsRenameMapping);
if (!entityType.Abstract)
{
typeChoices.Add(entityType, entityColumnMap);
}
if (entityType == baseStructuralType)
{
baseTypeColumnMaps = propertyColumnMaps;
}
}
// NOTE: We don't have a null sentinel here, because the stored proc won't
// return one anyway; we'll just presume the data's always there.
var polymorphicMap = new MultipleDiscriminatorPolymorphicColumnMap(
TypeUsage.Create(baseStructuralType), baseStructuralType.Name, baseTypeColumnMaps, discriminatorColumns, typeChoices,
(object[] discriminatorValues) => mapping.Discriminate(discriminatorValues, resultSetIndex));
CollectionColumnMap collection = new SimpleCollectionColumnMap(
baseStructuralType.GetCollectionType().TypeUsage, baseStructuralType.Name, polymorphicMap, null, null);
return collection;
}
示例12: TryGetMember
/// <summary>
/// Given the type in the target space and the member name in the source space,
/// get the corresponding member in the target space
/// For e.g. consider a Conceptual Type Foo with a member bar and a CLR type
/// XFoo with a member YBar. If one has a reference to Foo one can
/// invoke GetMember(Foo,"YBar") to retrieve the member metadata for bar
/// </summary>
/// <param name="type"> The type in the target perspective </param>
/// <param name="memberName"> the name of the member in the source perspective </param>
/// <param name="ignoreCase"> true for case-insensitive lookup </param>
/// <param name="outMember"> returns the edmMember if a match is found </param>
/// <returns> true if a match is found, otherwise false </returns>
internal override bool TryGetMember(StructuralType type, String memberName, bool ignoreCase, out EdmMember outMember)
{
outMember = null;
Map map = null;
if (MetadataWorkspace.TryGetMap(type, DataSpace.OCSpace, out map))
{
var objectTypeMap = map as ObjectTypeMapping;
if (objectTypeMap != null)
{
var objPropertyMapping = objectTypeMap.GetMemberMapForClrMember(memberName, ignoreCase);
if (null != objPropertyMapping)
{
outMember = objPropertyMapping.EdmMember;
return true;
}
}
}
return false;
}
示例13: GetObjectMember
/// <summary>
/// Tries and get the mapping ospace member for the given edmMember and the ospace type
/// </summary>
/// <param name="edmMember"></param>
/// <param name="objectType"></param>
/// <returns></returns
private static EdmMember GetObjectMember(EdmMember edmMember, StructuralType objectType)
{
// Assuming that we will have a single member in O-space for a member in C space
EdmMember objectMember;
if (!objectType.Members.TryGetValue(edmMember.Name, false /*ignoreCase*/, out objectMember))
{
throw new MappingException(
Strings.Mapping_Default_OCMapping_Clr_Member(
edmMember.Name, edmMember.DeclaringType.FullName, objectType.FullName));
}
return objectMember;
}
示例14: GetClrType
public Type GetClrType(StructuralType edmType)
{
throw new NotImplementedException();
}
示例15: TryFindAndCreatePrimitiveProperties
private bool TryFindAndCreatePrimitiveProperties(
Type type, StructuralType cspaceType, StructuralType ospaceType, IEnumerable<PropertyInfo> clrProperties)
{
foreach (
var cspaceProperty in
cspaceType.GetDeclaredOnlyMembers<EdmProperty>().Where(p => Helper.IsPrimitiveType(p.TypeUsage.EdmType)))
{
var clrProperty = clrProperties.FirstOrDefault(p => MemberMatchesByConvention(p, cspaceProperty));
if (clrProperty != null)
{
PrimitiveType propertyType;
if (TryGetPrimitiveType(clrProperty.PropertyType, out propertyType))
{
if (clrProperty.CanRead
&& clrProperty.CanWriteExtended())
{
AddScalarMember(type, clrProperty, ospaceType, cspaceProperty, propertyType);
}
else
{
var message = Strings.Validator_OSpace_Convention_ScalarPropertyMissginGetterOrSetter(
clrProperty.Name, type.FullName, type.Assembly().FullName);
LogLoadMessage(message, cspaceType);
return false;
}
}
else
{
var message = Strings.Validator_OSpace_Convention_NonPrimitiveTypeProperty(
clrProperty.Name, type.FullName, clrProperty.PropertyType.FullName);
LogLoadMessage(message, cspaceType);
return false;
}
}
else
{
var message = Strings.Validator_OSpace_Convention_MissingRequiredProperty(cspaceProperty.Name, type.FullName);
LogLoadMessage(message, cspaceType);
return false;
}
}
return true;
}