Inheritance: MappingBase, IHasMappedMembers
Ejemplo n.º 1
0
        public void Map(ClassMappingBase classMap, Member member)
        {
            if (!(classMap is ClassMapping)) return;

            var version = new VersionMapping
            {
                ContainingEntityType = classMap.Type,
            };
            version.Set(x => x.Name, Layer.Defaults, member.Name);
            version.Set(x => x.Type, Layer.Defaults, GetDefaultType(member));
            var columnMapping = new ColumnMapping();
            columnMapping.Set(x => x.Name, Layer.Defaults, member.Name);
            version.AddColumn(Layer.Defaults, columnMapping);

            SetDefaultAccess(member, version);

            if (IsSqlTimestamp(member))
            {
                version.Columns.Each(column =>
                {
                    column.Set(x => x.SqlType, Layer.Defaults, "timestamp");
                    column.Set(x => x.NotNull, Layer.Defaults, true);
                });
                version.Set(x => x.UnsavedValue, Layer.Defaults, null);
            }

            ((ClassMapping)classMap).Set(x => x.Version, Layer.Defaults, version);
        }
Ejemplo n.º 2
0
        public void Map(ClassMappingBase classMap, PropertyInfo property)
        {
            if (property.DeclaringType != classMap.Type || !(classMap is ClassMapping))
                return;

            var version = new VersionMapping
            {
                Name = property.Name,
            };

            version.SetDefaultValue("Type", GetDefaultType(property));
            version.AddDefaultColumn(new ColumnMapping { Name = property.Name });

            if (IsSqlTimestamp(property))
            {
                version.Columns.Each(x =>
                {
                    x.SqlType = "timestamp";
                    x.NotNull = true;
                });
                version.UnsavedValue = null;
            }

            ((ClassMapping)classMap).Version = version;
        }
Ejemplo n.º 3
0
 public virtual void MapEverythingInClass(ClassMappingBase mapping, Type entityType, IList<string> mappedProperties)
 {
     foreach (var property in entityType.GetProperties())
     {
         TryToMapProperty(mapping, property.ToMember(), mappedProperties);
     }
 }
Ejemplo n.º 4
0
        public void Map(ClassMappingBase classMap, Member member)
        {
            if (!(classMap is ClassMapping)) return;

            var version = new VersionMapping
            {
                Name = member.Name,
                ContainingEntityType = classMap.Type,
            };

            version.SetDefaultValue("Type", GetDefaultType(member));
            version.AddDefaultColumn(new ColumnMapping { Name = member.Name });

            if (member.IsProperty && !member.CanWrite)
                version.Access = cfg.GetAccessStrategyForReadOnlyProperty(member).ToString();

            if (IsSqlTimestamp(member))
            {
                version.Columns.Each(x =>
                {
                    x.SqlType = "timestamp";
                    x.NotNull = true;
                });
                version.UnsavedValue = null;
            }

            ((ClassMapping)classMap).Version = version;
        }
Ejemplo n.º 5
0
        private void MapInheritanceTree(Type classType, ClassMappingBase mapping, IList<Member> mappedMembers)
        {
            var discriminatorSet = HasDiscriminator(mapping);
            var isDiscriminated = cfg.IsDiscriminated(classType) || discriminatorSet;
            var mappingTypesWithLogicalParents = GetMappingTypesWithLogicalParents();

            foreach (var inheritedClass in mappingTypesWithLogicalParents
                .Where(x => x.Value != null && x.Value.Type == classType)
                .Select(x => x.Key))
            {
                var tempMapping = mapping as ClassMapping;
                var tempIsNull = tempMapping == null;
                if (isDiscriminated && !discriminatorSet && !tempIsNull)
                {
                    var discriminatorColumn = cfg.GetDiscriminatorColumn(classType);
                    var discriminator = new DiscriminatorMapping
                    {
                        ContainingEntityType = classType,
                        Type = new TypeReference(typeof(string))
                    };
                    discriminator.AddDefaultColumn(new ColumnMapping { Name = discriminatorColumn });

                    tempMapping.Discriminator = discriminator;
                    discriminatorSet = true;
                }

                SubclassMapping subclassMapping;

                if(!tempIsNull && tempMapping.IsUnionSubclass)
                {
                    subclassMapping = new SubclassMapping(SubclassType.UnionSubclass)
                    {
                        Type = inheritedClass.Type
                    };
                }
                else if(!isDiscriminated)
                {
                    subclassMapping = new SubclassMapping(SubclassType.JoinedSubclass)
                    {
                        Type = inheritedClass.Type
                    };
                    subclassMapping.Key = new KeyMapping();
                    subclassMapping.Key.AddDefaultColumn(new ColumnMapping { Name = mapping.Type.Name + "_id" });
                }
                else
                    subclassMapping = new SubclassMapping(SubclassType.Subclass)
                    {
                        Type = inheritedClass.Type
                    };

				// track separate set of properties for each sub-tree within inheritance hierarchy
            	var subclassMembers = new List<Member>(mappedMembers);
				MapSubclass(subclassMembers, subclassMapping, inheritedClass);

                mapping.AddSubclass(subclassMapping);

				MergeMap(inheritedClass.Type, subclassMapping, subclassMembers);
            }
        }
 protected override void ProcessClassBase(ClassMappingBase classMapping)
 {
     if (!classMapping.IsNameSpecified)
     {
         if (classMapping.Type == null)
             throw new ConventionException("Cannot apply the naming convention. No type specified.", classMapping);
         classMapping.Name = DetermineNameFromType(classMapping.Type);
     }
 }
Ejemplo n.º 7
0
        public void Map(ClassMappingBase classMap, Member member)
        {
            // don't map the component here, mark it as a reference which'll
            // allow us to integrate with ComponentMap or automap at a later
            // stage
            var mapping = new ReferenceComponentMapping(ComponentType.Component, member, member.PropertyType, classMap.Type, cfg.GetComponentColumnPrefix(member));

            classMap.AddComponent(mapping);
        }
Ejemplo n.º 8
0
        public void Map(ClassMappingBase classMap, Member member)
        {
            if (!(classMap is ClassMapping)) {
                return;
            }

            var identity = ((ClassMapping) classMap).Id;
            if (identity == null) {
                var idMapping = new IdMapping {ContainingEntityType = classMap.Type};
                var columnMapping = new ColumnMapping();
                columnMapping.Set(x => x.Name, Layer.Defaults, member.Name);
                idMapping.AddColumn(Layer.Defaults, columnMapping);
                idMapping.Set(x => x.Name, Layer.Defaults, member.Name);
                idMapping.Set(x => x.Type, Layer.Defaults, new TypeReference(member.PropertyType));
                idMapping.Member = member;
                idMapping.Set(x => x.Generator, Layer.Defaults, GetDefaultGenerator(member));

                SetDefaultAccess(member, idMapping);

                identity = idMapping;
            }
            else {
                if (identity is IdMapping) {
                    var idMapping = identity as IdMapping;
                    var compositeId = new CompositeIdMapping {ContainingEntityType = classMap.Type};

                    var idKeyPropertyMapping = GetKeyPropertyMapping(classMap.Type, idMapping.Name,
                                                                     idMapping.Type.GetUnderlyingSystemType());

                    var keyPropertyMapping = GetKeyPropertyMapping(classMap.Type, member.Name,
                                                                   member.PropertyType);

                    compositeId.AddKey(idKeyPropertyMapping);
                    compositeId.AddKey(keyPropertyMapping);

                    identity = compositeId;
                }
                else if (identity is CompositeIdMapping) {
                    var compositeId = identity as CompositeIdMapping;

                    var keyPropertyMapping = GetKeyPropertyMapping(classMap.Type, member.Name,
                                                                   member.PropertyType);

                    compositeId.AddKey(keyPropertyMapping);

                    identity = compositeId;
                }
                else {
                    throw new NotImplementedException(
                        string.Format("Mayank: Fluent nhibernate not exended to support type '{0}'",
                                      identity.GetType().Name));
                }
            }

            ((ClassMapping) classMap).Set(x => x.Id, Layer.Defaults, identity);
        }
Ejemplo n.º 9
0
        private void SetRelationship(Member property, ClassMappingBase classMap, ICollectionMapping mapping)
        {
            var relationship = new OneToManyMapping
            {
                Class = new TypeReference(property.PropertyType.GetGenericArguments()[0]),
                ContainingEntityType = classMap.Type
            };

            mapping.SetDefaultValue(x => x.Relationship, relationship);
        }
Ejemplo n.º 10
0
        private void SetKey(Member property, ClassMappingBase classMap, ICollectionMapping mapping)
        {
            var columnName = property.DeclaringType.Name + "_id";
            var key = new KeyMapping();

            key.ContainingEntityType = classMap.Type;
            key.AddDefaultColumn(new ColumnMapping { Name = columnName });

            mapping.SetDefaultValue(x => x.Key, key);
        }
        public void Map(ClassMappingBase classMap, Member property)
        {
            var inverseProperty = GetInverseProperty(property);
            var parentSide = expressions.GetParentSideForManyToMany(property.DeclaringType, inverseProperty.DeclaringType);
            var mapping = GetCollection(property);

            ConfigureModel(property, mapping, classMap, parentSide);

            classMap.AddCollection(mapping);
        }
Ejemplo n.º 12
0
        public void Map(ClassMappingBase classMap, Member member)
        {
            var inverseProperty = GetInverseProperty(member);
            var parentSide = cfg.GetParentSideForManyToMany(member.DeclaringType, inverseProperty.DeclaringType);
            var mapping = GetCollection(member);

            ConfigureModel(member, mapping, classMap, parentSide);

            classMap.AddCollection(mapping);
        }
        public void Map(ClassMappingBase classMap, Member property)
        {
            if (property.DeclaringType != classMap.Type)
                return;

            if (simpleTypeCollectionStep.MapsProperty(property))
                simpleTypeCollectionStep.Map(classMap, property);
            else if (entityCollectionStep.MapsProperty(property))
                entityCollectionStep.Map(classMap, property);
        }
Ejemplo n.º 14
0
        public void Map(ClassMappingBase classMap, Member member)
        {
            if (member.DeclaringType != classMap.Type)
                return;

            if (simpleTypeCollectionStepStep.ShouldMap(member))
                simpleTypeCollectionStepStep.Map(classMap, member);
            else if (collectionStep.ShouldMap(member))
                collectionStep.Map(classMap, member);
        }
Ejemplo n.º 15
0
        static void SetRelationship(Member property, ClassMappingBase classMap, CollectionMapping mapping)
        {
            var relationship = new OneToManyMapping
            {
                ContainingEntityType = classMap.Type
            };
            relationship.Set(x => x.Class, Layer.Defaults, new TypeReference(property.PropertyType.GetGenericArguments()[0]));

            mapping.Set(x => x.Relationship, Layer.Defaults, relationship);
        }
Ejemplo n.º 16
0
        private void ApplyOverrides(Type classType, IList<Member> mappedMembers, ClassMappingBase mapping)
        {
            var autoMapType = typeof(AutoMapping<>).MakeGenericType(classType);
            var autoMap = Activator.CreateInstance(autoMapType, mappedMembers);

            inlineOverrides
                .Where(x => x.CanOverride(classType))
                .Each(x => x.Apply(autoMap));

            ((IAutoClasslike)autoMap).AlterModel(mapping);
        }
Ejemplo n.º 17
0
        private void ApplyOverrides(Type classType, IList<Member> mappedMembers, ClassMappingBase mapping)
        {
            var autoMapType = ReflectionHelper.AutomappingTypeForEntityType(classType);
            var autoMap = Activator.CreateInstance(autoMapType, mappedMembers);

            inlineOverrides
                .Where(x => x.CanOverride(classType))
                .Each(x => x.Apply(autoMap));

            ((IAutoClasslike)autoMap).AlterModel(mapping);
        }
        public void Map(ClassMappingBase classMap, Member member)
        {
            if (_defaultManyToManyStep.ShouldMap(member))
            {
                _defaultManyToManyStep.Map(classMap, member);
                return;
            }

            var collection = CreateManyToMany(classMap, member);
            classMap.AddCollection(collection);
        }
Ejemplo n.º 19
0
        public void Map(ClassMappingBase classMap, PropertyInfo property)
        {
            if (property.DeclaringType != classMap.Type || !(classMap is ClassMapping))
                return;

            ((ClassMapping)classMap).Version = new VersionMapping
            {
                Name = property.Name,
                Column = property.Name
            };
        }
        private static void SetKey(Member property, ClassMappingBase classMap, CollectionMapping mapping)
        {
            var ColumnName = "Id_"+property.DeclaringType.Name;
            var ColumnMapping = new ColumnMapping();
            ColumnMapping.Set(x => x.Name, Layer.Defaults, ColumnName);

            var Key = new KeyMapping {ContainingEntityType = classMap.Type};
            Key.AddColumn(Layer.Defaults, ColumnMapping);

            mapping.Set(x => x.Key, Layer.Defaults, Key);
        }
        private void SetElement(Member property, ClassMappingBase classMap, ICollectionMapping mapping)
        {
            var element = new ElementMapping
            {
                ContainingEntityType = classMap.Type,
                Type = new TypeReference(property.PropertyType.GetGenericArguments()[0])
            };

            element.AddDefaultColumn(new ColumnMapping { Name = cfg.SimpleTypeCollectionValueColumn(property) });
            mapping.SetDefaultValue(x => x.Element, element);
        }
Ejemplo n.º 22
0
        public void Map(ClassMappingBase classMap, Member property)
        {
            if (!(classMap is ClassMapping)) return;

            var idMapping = new IdMapping { ContainingEntityType = classMap.Type };
            idMapping.AddDefaultColumn(new ColumnMapping() { Name = property.Name });
            idMapping.Name = property.Name;
            idMapping.Type = new TypeReference(property.PropertyType);
            idMapping.Member = property;
            idMapping.SetDefaultValue("Generator", GetDefaultGenerator(property));
            ((ClassMapping)classMap).Id = idMapping;        
        }
Ejemplo n.º 23
0
 public bool Equals(ClassMappingBase other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(Equals(other.mappedMembers, mappedMembers) &&
            other.subclasses.ContentEquals(subclasses));
 }
        private void SetElement(Member property, ClassMappingBase classMap, CollectionMapping mapping)
        {
            var element = new ElementMapping
            {
                ContainingEntityType = classMap.Type,
            };
            element.Set(x => x.Type, Layer.Defaults, new TypeReference(property.PropertyType.GetGenericArguments()[0]));

            var columnMapping = new ColumnMapping();
            columnMapping.Set(x => x.Name, Layer.Defaults, cfg.SimpleTypeCollectionValueColumn(property));
            element.AddColumn(Layer.Defaults, columnMapping);
            mapping.Set(x => x.Element, Layer.Defaults, element);
        }
        private void SetKey(PropertyInfo property, ClassMappingBase classMap, ICollectionMapping mapping)
        {
            var columnName = property.DeclaringType.Name + "_Id";

            if (classMap is ComponentMapping)
                columnName = expressions.GetComponentColumnPrefix(((ComponentMapping)classMap).PropertyInfo) + columnName;

            var key = new KeyMapping();

            key.AddDefaultColumn(new ColumnMapping { Name = columnName});

            mapping.SetDefaultValue(x => x.Key, key);
        }
Ejemplo n.º 26
0
        private void ConfigureModel(PropertyInfo property, ICollectionMapping mapping, ClassMappingBase classMap, Type parentSide)
        {
            // TODO: Make the child type safer
            mapping.SetDefaultValue(x => x.Name, property.Name);
            mapping.Relationship = CreateManyToMany(property, property.PropertyType.GetGenericArguments()[0], classMap.Type);
            mapping.ContainingEntityType = classMap.Type;
            mapping.Key = new KeyMapping();
            mapping.ChildType = property.PropertyType.GetGenericArguments()[0];
            mapping.MemberInfo = property;

            if (parentSide != property.DeclaringType)
                mapping.Inverse = true;
        }
Ejemplo n.º 27
0
        public ClassMappingBase MergeMap(Type classType, ClassMappingBase mapping, IList<Member> mappedMembers)
        {
            // map class first, then subclasses - this way subclasses can inspect the class model
            // to see which properties have already been mapped
            ApplyOverrides(classType, mappedMembers, mapping);

            ProcessClass(mapping, classType, mappedMembers);

            if (mappingTypes != null)
                MapInheritanceTree(classType, mapping, mappedMembers);

            return mapping;
        }
        private void SetKey(Member property, ClassMappingBase classMap, ICollectionMapping mapping)
        {
            var columnName = property.DeclaringType.Name + "_id";

            if (classMap is ComponentMapping)
                columnName = cfg.GetComponentColumnPrefix(((ComponentMapping)classMap).Member) + columnName;

            var key = new KeyMapping();

            key.ContainingEntityType = classMap.Type;
            key.AddDefaultColumn(new ColumnMapping { Name = columnName });

            mapping.SetDefaultValue(x => x.Key, key);
        }
Ejemplo n.º 29
0
        public override void MapEverythingInClass(ClassMappingBase mapping, Type entityType, IList<string> mappedProperties)
        {
            // This will ONLY map private properties. Do not call base.

            var rule = localExpressions.FindMappablePrivateProperties;
            if (rule == null)
                throw new InvalidOperationException("The FindMappablePrivateProperties convention must be supplied to use the PrivateAutoMapper. ");

            foreach (var property in entityType.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic))
            {
                if (rule(property))
                    TryToMapProperty(mapping, property, mappedProperties);
            }
        }
Ejemplo n.º 30
0
        public void SetKey(Member property, ClassMappingBase classMap, CollectionMapping mapping)
        {
            var columnName = property.DeclaringType.Name + "_id";
            var key = new KeyMapping
            {
                ContainingEntityType = classMap.Type
            };

            var columnMapping = new ColumnMapping();
            columnMapping.Set(x => x.Name, Layer.Defaults, columnName);
            key.AddColumn(Layer.Defaults, columnMapping);

            mapping.Set(x => x.Key, Layer.Defaults, key);
        }
Ejemplo n.º 31
0
        public void SetKey(Member property, ClassMappingBase classMap, ICollectionMapping mapping)
        {
            var columnName = String.Format("{0}_{1}_id", property.DeclaringType.Name, property.Name);

            if (classMap is ComponentMapping)
                columnName = expressions.GetComponentColumnPrefix(((ComponentMapping)classMap).Member) + columnName;

            var key = new KeyMapping();

            key.ContainingEntityType = classMap.Type;
            key.AddDefaultColumn(new ColumnMapping { Name = columnName });

            mapping.SetDefaultValue(x => x.Key, key);
        }