public override string GetTableName(MappingEntity entity) { AttributeMappingEntity en = (AttributeMappingEntity)entity; var table = en.Tables.FirstOrDefault(); return(this.GetTableName(table)); }
public override string GetTableName(MappingEntity entity) { AttributeMappingEntity entity2 = (AttributeMappingEntity)entity; MappingTable table = entity2.Tables.FirstOrDefault <MappingTable>(); return(this.GetTableName(table)); }
private MappingEntity CreateEntity(Type elementType, string tableId, Type entityType) { if (tableId == null) { tableId = this.GetTableId(elementType); } HashSet <string> set = new HashSet <string>(); List <AttributeMappingMember> mappingMembers = new List <AttributeMappingMember>(); int index = tableId.IndexOf('.'); string rootEntityId = (index > 0) ? tableId.Substring(0, index) : tableId; string path = (index > 0) ? tableId.Substring(index + 1) : ""; IEnumerable <MappingAttribute> mappingAttributes = this.GetMappingAttributes(rootEntityId); IOrderedEnumerable <TableBaseAttribute> source = from ta in mappingAttributes.OfType <TableBaseAttribute>() orderby ta.Name select ta; TableAttribute attribute = source.OfType <TableAttribute>().FirstOrDefault <TableAttribute>(); if (((attribute != null) && (attribute.EntityType != null)) && (entityType == elementType)) { entityType = attribute.EntityType; } IOrderedEnumerable <MemberAttribute> enumerable3 = from ma in mappingAttributes.OfType <MemberAttribute>() where ma.Member.StartsWith(path) orderby ma.Member select ma; foreach (MemberAttribute attribute2 in enumerable3) { if (!string.IsNullOrEmpty(attribute2.Member)) { string str2 = (path.Length == 0) ? attribute2.Member : attribute2.Member.Substring(path.Length + 1); MemberInfo mi = null; MemberAttribute attribute3 = null; AttributeMappingEntity nested = null; if (str2.Contains <char>('.')) { string str3 = str2.Substring(0, str2.IndexOf('.')); if (str3.Contains <char>('.') || set.Contains(str3)) { continue; } set.Add(str3); mi = this.FindMember(entityType, str3); string entityID = tableId + "." + str3; nested = (AttributeMappingEntity)this.GetEntity(King.Framework.Linq.TypeHelper.GetMemberType(mi), entityID); } else { if (set.Contains(str2)) { throw new InvalidOperationException(string.Format("AttributeMapping: more than one mapping attribute specified for member '{0}' on type '{1}'", str2, entityType.Name)); } mi = this.FindMember(entityType, str2); attribute3 = attribute2; } mappingMembers.Add(new AttributeMappingMember(mi, attribute3, nested)); } } return(new AttributeMappingEntity(elementType, tableId, entityType, source, mappingMembers)); }
private MemberInfo GetReferencedMember(AttributeMappingEntity entity, string name, string source, Type sourceType) { var mm = entity.GetMappingMember(name); if (mm == null) { throw new InvalidOperationException(string.Format("AttributeMapping: The member '{0}.{1}' referenced in {2} for '{3}' is not mapped or does not exist", entity.EntityType.Name, name, source, sourceType.Name)); } return(mm.Member); }
public override IEnumerable <MemberInfo> GetAssociationKeyMembers(MappingEntity entity, MemberInfo member) { AttributeMappingEntity thisEntity = (AttributeMappingEntity)entity; AttributeMappingMember mm = thisEntity.GetMappingMember(member.Name); if (mm != null && mm.Association != null) { return(this.GetReferencedMembers(thisEntity, mm.Association.KeyMembers, "Association.KeyMembers", thisEntity.EntityType)); } return(base.GetAssociationKeyMembers(entity, member)); }
public override IEnumerable <MemberInfo> GetAssociationKeyMembers(MappingEntity entity, MemberInfo member) { AttributeMappingEntity entity2 = (AttributeMappingEntity)entity; AttributeMappingMember mappingMember = entity2.GetMappingMember(member.Name); if ((mappingMember != null) && (mappingMember.Association != null)) { return(this.GetReferencedMembers(entity2, mappingMember.Association.KeyMembers, "Association.KeyMembers", entity2.EntityType)); } return(base.GetAssociationKeyMembers(entity, member)); }
public override MappingEntity GetRelatedEntity(MappingEntity entity, MemberInfo member) { AttributeMappingEntity thisEntity = (AttributeMappingEntity)entity; AttributeMappingMember mm = thisEntity.GetMappingMember(member.Name); if (mm != null) { if (mm.Association != null) { Type elementType = TypeHelper.GetElementType(TypeHelper.GetMemberType(member)); Type entityType = (mm.Association.RelatedEntityType != null) ? mm.Association.RelatedEntityType : elementType; return(this.GetReferencedEntity(elementType, mm.Association.RelatedEntityID, entityType, "Association.RelatedEntityID")); } else if (mm.NestedEntity != null) { return(mm.NestedEntity); } } return(base.GetRelatedEntity(entity, member)); }
internal AttributeMappingTable(AttributeMappingEntity entity, TableBaseAttribute attribute) { this.entity = entity; this.attribute = attribute; }
internal AttributeMappingMember(MemberInfo member, MemberAttribute attribute, AttributeMappingEntity nested) { this.member = member; this.attribute = attribute; this.nested = nested; }
private IEnumerable <MemberInfo> GetReferencedMembers(AttributeMappingEntity entity, string names, string source, Type sourceType) { return(names.Split(separators).Select(n => this.GetReferencedMember(entity, n, source, sourceType))); }
private MappingEntity CreateEntity(Type elementType, string tableId, Type entityType) { if (tableId == null) { tableId = this.GetTableId(elementType); } var members = new HashSet <string>(); var mappingMembers = new List <AttributeMappingMember>(); int dot = tableId.IndexOf('.'); var rootTableId = dot > 0 ? tableId.Substring(0, dot) : tableId; var path = dot > 0 ? tableId.Substring(dot + 1) : ""; var mappingAttributes = this.GetMappingAttributes(rootTableId); var tableAttributes = mappingAttributes.OfType <TableBaseAttribute>() .OrderBy(ta => ta.Name); var tableAttr = tableAttributes.OfType <TableAttribute>().FirstOrDefault(); if (tableAttr != null && tableAttr.EntityType != null && entityType == elementType) { entityType = tableAttr.EntityType; } var memberAttributes = mappingAttributes.OfType <MemberAttribute>() .Where(ma => ma.Member.StartsWith(path)) .OrderBy(ma => ma.Member); foreach (var attr in memberAttributes) { if (string.IsNullOrEmpty(attr.Member)) { continue; } string memberName = (path.Length == 0) ? attr.Member : attr.Member.Substring(path.Length + 1); MemberInfo member = null; MemberAttribute attribute = null; AttributeMappingEntity nested = null; if (memberName.Contains('.')) // additional nested mappings { string nestedMember = memberName.Substring(0, memberName.IndexOf('.')); if (nestedMember.Contains('.')) { continue; // don't consider deeply nested members yet } if (members.Contains(nestedMember)) { continue; // already seen it (ignore additional) } members.Add(nestedMember); member = this.FindMember(entityType, nestedMember); string newTableId = tableId + "." + nestedMember; nested = (AttributeMappingEntity)this.GetEntity(TypeHelper.GetMemberType(member), newTableId); } else { if (members.Contains(memberName)) { throw new InvalidOperationException(string.Format("AttributeMapping: more than one mapping attribute specified for member '{0}' on type '{1}'", memberName, entityType.Name)); } member = this.FindMember(entityType, memberName); attribute = attr; } mappingMembers.Add(new AttributeMappingMember(member, attribute, nested)); } return(new AttributeMappingEntity(elementType, tableId, entityType, tableAttributes, mappingMembers)); }
/// <summary> /// Create a <see cref="MappingEntity"/>. /// </summary> /// <param name="entityType">The entity type this mapping is for.</param> /// <param name="entityId">The mapping id of the entity type.</param> /// <param name="parent"></param> private MappingEntity CreateEntity(Type entityType, string entityId, ParentEntity parent) { var members = new HashSet <string>(); var mappingMembers = new List <AttributeMappingMember>(); // get the attributes given the type that has the mappings (root type, in case of nested entity) var mappingAttributes = this.GetMappingAttributes(entityType, entityId, parent); var tableAttributes = mappingAttributes.OfType <TableBaseAttribute>() .OrderBy(ta => ta.Name); var staticType = entityType; var runtimeType = entityType; // check to see if mapping attributes tell us about a different runtime. var entityAttr = mappingAttributes.OfType <EntityAttribute>().FirstOrDefault(); if (entityAttr != null && entityAttr.RuntimeType != null && parent == null) { runtimeType = entityAttr.RuntimeType; } var memberAttributes = mappingAttributes.OfType <MemberAttribute>() .OrderBy(ma => ma.Member); foreach (var attr in memberAttributes) { if (string.IsNullOrEmpty(attr.Member)) { continue; } var memberName = attr.Member; MemberInfo member = null; MemberAttribute attribute = null; AttributeMappingEntity nested = null; var nestedEntity = attr as NestedEntityAttribute; if (nestedEntity != null) { members.Add(memberName); member = this.FindMember(entityType, memberName); var nestedEntityId = entityId + "." + memberName; var nestedEntityType = TypeHelper.GetMemberType(member); nested = (AttributeMappingEntity)this.GetEntity(nestedEntityType, nestedEntityId, new ParentEntity(parent, member, entityType, entityId)); } else { if (members.Contains(memberName)) { throw new InvalidOperationException(string.Format("AttributeMapping: more than one mapping attribute specified for member '{0}' on type '{1}'", memberName, entityType.Name)); } member = this.FindMember(entityType, memberName); attribute = attr; } mappingMembers.Add(new AttributeMappingMember(member, attribute, nested)); } return(new AttributeMappingEntity(staticType, runtimeType, entityId, tableAttributes, mappingMembers)); }
private MemberInfo GetReferencedMember(AttributeMappingEntity entity, string name, string source, Type sourceType) { var mm = entity.GetMappingMember(name); if (mm == null) { throw new InvalidOperationException(string.Format("AttributeMapping: The member '{0}.{1}' referenced in {2} for '{3}' is not mapped or does not exist", entity.EntityType.Name, name, source, sourceType.Name)); } return mm.Member; }
private IEnumerable<MemberInfo> GetReferencedMembers(AttributeMappingEntity entity, string names, string source, Type sourceType) { return names.Split(separators).Select(n => this.GetReferencedMember(entity, n, source, sourceType)); }