Inheritance: FluentNHibernate.MappingModel.MappingBase, INameable
        public void Should_produce_valid_hbm()
        {
            var column = new ColumnMapping() {Name = "Column1"};
            var writer = new HbmColumnWriter();

            writer.ShouldGenerateValidOutput(column);
        }
 public void Add(string columnName, Action<ColumnPart> customColumnMapping)
 {
     var column = new ColumnMapping(sharedAttributes) { Name = columnName };
     var part = new ColumnPart(column);
     customColumnMapping(part);
     mapping.AddColumn(column);
 }
        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);
        }
Exemple #4
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,
                    };
                    discriminator.Set(x => x.Type, Layer.Defaults, new TypeReference(typeof(string)));
                    var columnMapping = new ColumnMapping();
                    columnMapping.Set(x => x.Name, Layer.Defaults, discriminatorColumn);
                    discriminator.AddColumn(Layer.Defaults, columnMapping);

                    tempMapping.Set(x => x.Discriminator, Layer.Defaults, discriminator);
                    discriminatorSet = true;
                }

                SubclassMapping subclassMapping;

                if(!tempIsNull && tempMapping.IsUnionSubclass)
                {
                    subclassMapping = new SubclassMapping(SubclassType.UnionSubclass);
                    subclassMapping.Set(x => x.Type, Layer.Defaults, inheritedClass.Type);
                }
                else if(!isDiscriminated)
                {
                    subclassMapping = new SubclassMapping(SubclassType.JoinedSubclass);
                    subclassMapping.Set(x => x.Type, Layer.Defaults, inheritedClass.Type);
                    subclassMapping.Set(x => x.Key, Layer.Defaults, new KeyMapping());
                    var columnMapping = new ColumnMapping();
                    columnMapping.Set(x => x.Name, Layer.Defaults, mapping.Type.Name + "_id");
                    subclassMapping.Key.AddColumn(Layer.Defaults, columnMapping);
                }
                else
                {
                    subclassMapping = new SubclassMapping(SubclassType.Subclass);
                    subclassMapping.Set(x => x.Type, Layer.Defaults, 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 virtual void BindColumn(SimpleValue model, ColumnMapping columnMapping)
 {
     Table table = model.Table;
     var column = CreateColumn(model, columnMapping);
     if (table != null)
         table.AddColumn(column);
     model.AddColumn(column);
 }
        public KeyPropertyPart ColumnName(string columnName)
        {
            var column = new ColumnMapping();
            column.Set(x => x.Name, Layer.UserSupplied, columnName);

            mapping.AddColumn(column);
            return this;
        }
        public void Should_apply_to_column_mapping()
        {
            var propertyInfo = ReflectionHelper.GetProperty((Album a) => a.ID);
            var columnMapping = new ColumnMapping { PropertyInfo = propertyInfo };

            _namingConvention.ProcessColumn(columnMapping);

            columnMapping.Name.ShouldEqual(columnMapping.PropertyInfo.Name);
        }
Exemple #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);
        }
        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);
        }
 public void Map(ClassMapping classMap)
 {
     var idProperty = classMap.Type.GetProperty("Id");
     var columnMapping = new ColumnMapping { Name = "Id", MappedMember = idProperty };
     var mapping = new IdMapping(columnMapping)
                       {
                           Name = "Id",
                           Generator = new IdGeneratorMapping()
                       };
     mapping.BindToMember(idProperty);
     classMap.Id = mapping;
 }
        static ICollectionRelationshipMapping CreateManyToMany(Member member, Type parentType, Type childType)
        {
            var columnMapping = new ColumnMapping();
            columnMapping.Set(x => x.Name, Layer.Defaults, childType.Name + "Id");

            var mapping = new ManyToManyMapping { ContainingEntityType = parentType };
            mapping.Set(x => x.Class, Layer.Defaults, new TypeReference(childType));
            mapping.Set(x => x.ParentType, Layer.Defaults, parentType);
            mapping.Set(x => x.ChildType, Layer.Defaults, childType);
            mapping.AddColumn(Layer.Defaults, columnMapping);

            return mapping;
        }
        private static ICollectionRelationshipMapping CreateManyToMany(Member member, Type parentType, Type childType)
        {
            var ColumnMapping = new ColumnMapping();
            ColumnMapping.Set(x => x.Name, Layer.Defaults, "Id_" + childType.Name);

            var Mapping = new ManyToManyMapping {ContainingEntityType = parentType};
            Mapping.Set(x => x.Class, Layer.Defaults, new FluentNHibernate.MappingModel.TypeReference(childType));
            Mapping.Set(x => x.ParentType, Layer.Defaults, parentType);
            Mapping.Set(x => x.ChildType, Layer.Defaults, childType);
            Mapping.AddColumn(Layer.Defaults, ColumnMapping);

            return Mapping;
        }
        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);
        }
        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);
        }
        static ICollectionRelationshipMapping CreateManyToMany(Member property, Type child, Type parent)
        {
            var mapping = new ManyToManyMapping
            {
                ContainingEntityType = parent
            };
            mapping.Set(x => x.Class, Layer.Defaults, new TypeReference(property.PropertyType.GetGenericArguments()[0]));

            var columnMapping = new ColumnMapping();
            columnMapping.Set(x => x.Name, Layer.Defaults, child.Name + "_id");
            mapping.AddColumn(Layer.Defaults, columnMapping);

            return mapping;
        }
        private ManyToOneMapping CreateMapping(Member member)
        {
            var mapping = new ManyToOneMapping { Member = member };

            mapping.Set(x => x.Name, Layer.Defaults, member.Name);
            mapping.Set(x => x.Class, Layer.Defaults, new TypeReference(member.PropertyType));
            var columnMapping = new ColumnMapping();
            columnMapping.Set(x => x.Name, Layer.Defaults, member.Name + "_id");
            mapping.AddColumn(Layer.Defaults, columnMapping);

            SetDefaultAccess(member, mapping);

            return mapping;
        }
Exemple #17
0
        public void Map(ClassMappingBase classMap, Member member)
        {
            if (!(classMap is ClassMapping)) return;

            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);

            ((ClassMapping)classMap).Set(x => x.Id, Layer.Defaults, idMapping);        
        }
        private PropertyMapping GetPropertyMapping(Type type, Member property)
        {
            var mapping = new PropertyMapping
            {
                ContainingEntityType = type,
                Member = property
            };

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

            mapping.Set(x => x.Name, Layer.Defaults, mapping.Member.Name);
            mapping.Set(x => x.Type, Layer.Defaults, GetDefaultType(property));

            SetDefaultAccess(property, mapping);

            return mapping;
        }
 public void AddDefaultColumn(ColumnMapping column)
 {
     columns.AddDefault(column);
 }
 public ColumnInstance(Type parentType, ColumnMapping mapping)
     : base(parentType, mapping)
 {
     this.mapping = mapping;
 }
 public void AddDefaultColumn(ColumnMapping mapping)
 {
     columns.AddDefault(mapping);
 }
 public void AddColumn(ColumnMapping mapping)
 {
     columns.Add(mapping);
 }
 public override void Visit(ColumnMapping columnMapping)
 {
     columnMapping.AcceptVisitor(this);
 }
 public ColumnInspector(Type containingEntityType, ColumnMapping mapping)
 {
     EntityType = containingEntityType;
     this.mapping = mapping;
 }
 public void SetUp()
 {
     this.mapping = new ColumnMapping();
     this.columnPart = new ColumnPart(mapping);
 }
 protected virtual Column CreateColumn(IValue value, ColumnMapping columnMapping)
 {
     var columnName = columnMapping.Name;
     if (columnName.IsNullOrEmpty())
         columnName = this.mappings.NamingStrategy.ColumnName(columnMapping.PropertyInfo.Name);
     var column = new Column(columnName)
     {
         Value = value,
         IsNullable = (!columnMapping.IsNotNullable),
         Length=columnMapping.Length,
         CheckConstraint = columnMapping.Check,
         IsUnique=columnMapping.IsUnique,
         SqlType=columnMapping.SqlType,
     };
     return column;
 }
 public void CreateDsl()
 {
     mapping = new ColumnMapping();
     inspector = new ColumnInspector(typeof(Record), mapping);
 }
 public virtual void ProcessColumn(ColumnMapping columnMapping)
 {
 }
 public void AddColumn(ColumnMapping column)
 {
     columns.Add(column);
 }
Exemple #30
0
 public ColumnPart(ColumnMapping columnMapping)
 {
     this.columnMapping = columnMapping;
 }
 public void AddColumn(ColumnMapping mapping)
 {
     columns.Add(mapping);
 }
 public virtual void Visit(ColumnMapping columnMapping)
 {
 }
 public override void ProcessColumn(ColumnMapping columnMapping)
 {
     if (prefixes.Any())
         columnMapping.Set(x => x.Name, Layer.UserSupplied, GetPrefix() + columnMapping.Name);
 }
 public override void ProcessColumn(ColumnMapping columnMapping)
 {
     if (prefixes.Any())
         columnMapping.Name = GetPrefix() + columnMapping.Name;
 }
 public bool Equals(ColumnMapping other)
 {
     return(Equals(other.attributes, attributes) && Equals(other.Member, Member));
 }