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)); }
internal AttributeMappingMember(MemberInfo member, MemberAttribute attribute, AttributeMapping.AttributeMappingEntity nested) { this.member = member; this.attribute = attribute; this.nested = nested; }