private Dictionary <string, string> GetRelationKeysMapFromRelationType(string typeName) { Dictionary <string, string> retMap = new Dictionary <string, string>(); DynEntityType type = DynEntityTypeManager.GetEntityTypeMandatory(typeName); foreach (DynPropertyConfiguration item in type.GetProperties()) { object[] attrs = item.GetCustomAttributes(typeof(RelationKeyDynAttribute), item.IsInherited); if (attrs.Length > 0) { RelationKeyDynAttribute rka = (RelationKeyDynAttribute)attrs[0]; try { retMap.Add(rka.RelatedType, item.Name); } catch { throw new NotSupportedException("Many to many relaion only supports single primary key entities."); } } } if (retMap.Count != 2) { throw new NotSupportedException("Relation entity could and must exactly contain two related key properties."); } return(retMap); }
/// <summary> /// Initializes a new instance of the <see cref="ManyToManyQueryDynAttribute"/> class. /// </summary> /// <param name="relationType">Type of the relation entity.</param> public ManyToManyQueryDynAttribute(string relationName) : base(QueryType.ManyToManyQuery) { DynEntityType relationType = DynEntityTypeManager.GetEntityType(relationName); if (relationType == null) { throw new NotSupportedException("A entity type's relation entity type is not find, if you use it as ManyToMany attribute's relation type parameter."); } EntityDynAttribute[] attrs = relationType.GetCustomAttributes(typeof(RelationDynAttribute), true); if (attrs == null || attrs.Length == 0) { throw new NotSupportedException("A entity type must be a relation entity type, if you use it as ManyToMany attribute's relation type parameter."); } this.relationType = relationName; }
/// <summary> /// Gets the type of the pk property. /// </summary> /// <param name="type">The type.</param> /// <returns>The type.</returns> internal static string GetPkPropertyType(string typeName) { string retType = null; DynEntityType entityType = DynEntityTypeManager.GetEntityTypeMandatory(typeName); foreach (DynPropertyConfiguration item in entityType.GetProperties()) { if (item.GetCustomAttributes(typeof(PrimaryKeyDynAttribute), item.IsInherited) != null) { retType = item.PropertyType; break; } } if (retType == null) { //check base entities foreach (DynEntityType baseType in entityType.GetAllBaseEntityTypes()) { foreach (DynPropertyConfiguration item in baseType.GetProperties()) { if (item.GetCustomAttributes(typeof(PrimaryKeyDynAttribute), item.IsInherited) != null) { retType = item.PropertyType; break; } } if (retType != null) { break; } } } return(retType); }