Exemple #1
0
 internal AttributeMappingMember(MemberInfo member, MemberAttribute attribute, AttributeMappingEntity nested)
 {
     this.member    = member;
     this.attribute = attribute;
     this.nested    = nested;
 }
Exemple #2
0
 internal CompositiveMappingMember(MemberInfo member, MemberAttribute attribute)
 {
     this.member    = member;
     this.attribute = attribute;
 }
Exemple #3
0
        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));
        }