Inheritance: FluentNHibernate.MappingModel.MappingBase
        public void Should_produce_valid_hbm()
        {
            var discriminator = new DiscriminatorMapping();

            var writer = new HbmDiscriminatorWriter(null);
            writer.ShouldGenerateValidOutput(discriminator);
        }
        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);
            }
        }
 public bool Equals(DiscriminatorMapping other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return Equals(other.ContainingEntityType, ContainingEntityType) &&
         other.Columns.ContentEquals(Columns) &&
         Equals(other.attributes, attributes);
 }
        public void ShouldWriteColumns()
        {
            var mapping = new DiscriminatorMapping();

            mapping.AddColumn(new ColumnMapping { Name = "Column1" });

            writer.VerifyXml(mapping)
                .Element("column").Exists();
        }
        public void ShouldWriteColumns()
        {
            var mapping = new DiscriminatorMapping();

            mapping.AddColumn(Layer.Defaults, new ColumnMapping("Column1"));

            writer.VerifyXml(mapping)
                .Element("column").Exists();
        }
        public void Should_write_the_column()
        {
            var discriminator = new DiscriminatorMapping { Column = new ColumnMapping() };

            var columnWriter = MockRepository.GenerateStub<IXmlWriter<ColumnMapping>>();
            columnWriter.Expect(x => x.Write(discriminator.Column)).Return(new HbmColumn());

            var writer = new HbmDiscriminatorWriter(columnWriter);
            writer.VerifyXml(discriminator)
                .Element("column").Exists();
        }
 public bool Equals(DiscriminatorMapping other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(Equals(other.ContainingEntityType, ContainingEntityType) &&
            other.columns.ContentEquals(columns) &&
            Equals(other.attributes, attributes));
 }
        private void MapInheritanceTree(Type classType, ClassMappingBase mapping, IList<Member> mappedMembers)
        {
            var discriminatorSet = false;
            var isDiscriminated = cfg.IsDiscriminated(classType);

            foreach (var inheritedClass in mappingTypes.Where(q =>
                q.Type.BaseType == classType &&
                    !cfg.IsConcreteBaseType(q.Type.BaseType)))
            {
                if (isDiscriminated && !discriminatorSet && mapping is ClassMapping)
                {
                    var discriminatorColumn = cfg.GetDiscriminatorColumn(classType);
                    var discriminator = new DiscriminatorMapping
                    {
                        ContainingEntityType = classType,
                        Type = new TypeReference(typeof(string))
                    };
                    discriminator.AddDefaultColumn(new ColumnMapping { Name = discriminatorColumn });

                    ((ClassMapping)mapping).Discriminator = discriminator;
                    discriminatorSet = true;
                }

                SubclassMapping subclassMapping;
                var subclassStrategy = cfg.GetSubclassStrategy(classType);

                if (subclassStrategy == SubclassStrategy.JoinedSubclass)
                {
                    subclassMapping = new SubclassMapping(SubclassType.JoinedSubclass);
                    subclassMapping.Key = new KeyMapping();
                    subclassMapping.Key.AddDefaultColumn(new ColumnMapping { Name = mapping.Type.Name + "_id" });
                }
                else
                    subclassMapping = new SubclassMapping(SubclassType.Subclass);

				// 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);
            }
        }
Example #9
0
 public override void Visit(DiscriminatorMapping discriminatorMapping)
 {
     discriminatorMapping.AcceptVisitor(this);
 }
 public DiscriminatorInspector(DiscriminatorMapping mapping)
 {
     this.mapping = mapping;
     propertyMappings.AutoMap();
 }
        public void Should_clear_the_parent_class_for_the_discriminator()
        {
            var classMap = new ClassMapping {Name = "class1" };
            var discriminator = new DiscriminatorMapping();

            classMap.Discriminator = discriminator;
            classMap.Discriminator = null;

            discriminator.ParentClass.ShouldBeNull();
        }
 public override void Visit(DiscriminatorMapping discriminatorMapping)
 {
     discriminatorMapping.AcceptVisitor(this);
 }
Example #13
0
        private void MapInheritanceTree(Type classType, ClassMappingBase mapping, IList<string> mappedProperties)
        {
            var discriminatorSet = false;
            var isDiscriminated = expressions.IsDiscriminated(classType);

            foreach (var inheritedClass in mappingTypes.Where(q =>
                q.Type.BaseType == classType &&
                    !expressions.IsConcreteBaseType(q.Type.BaseType)))
            {
                if (isDiscriminated && !discriminatorSet && mapping is ClassMapping)
                {
                    var discriminatorColumn = expressions.DiscriminatorColumn(classType);
                    var discriminator = new DiscriminatorMapping
                    {
                        ContainingEntityType = classType,
                        Type = new TypeReference(typeof(string))
                    };
                    discriminator.AddDefaultColumn(new ColumnMapping { Name = discriminatorColumn });

                    ((ClassMapping)mapping).Discriminator = discriminator;
                    discriminatorSet = true;
                }

                ISubclassMapping subclassMapping;
                var subclassStrategy = expressions.SubclassStrategy(classType);

                if (subclassStrategy == SubclassStrategy.JoinedSubclass)
                {
                    // TODO: This id name should be removed. Ideally it needs to be set by a
                    // default and be overridable by a convention (preferably the ForeignKey convention
                    // that already exists)
                    var subclass = new JoinedSubclassMapping
                    {
                        Type = inheritedClass.Type
                    };

                    subclass.Key = new KeyMapping();
                    subclass.Key.AddDefaultColumn(new ColumnMapping { Name = mapping.Type.Name + "_id" });

                    subclassMapping = subclass;
                }
                else
                    subclassMapping = new SubclassMapping();

                MapSubclass(mappedProperties, subclassMapping, inheritedClass);

                mapping.AddSubclass(subclassMapping);

                MergeMap(inheritedClass.Type, (ClassMappingBase)subclassMapping, mappedProperties);
            }
        }
Example #14
0
 public virtual void ProcessDiscriminator(DiscriminatorMapping discriminatorMapping)
 {
 }
Example #15
0
 public virtual void Visit(DiscriminatorMapping discriminatorMapping)
 {
 }
 public void CreateDsl()
 {
     mapping = new DiscriminatorMapping();
     inspector = new DiscriminatorInspector(mapping);
 }
 public virtual void Visit(DiscriminatorMapping discriminatorMapping)
 {
 }
 public virtual void ProcessDiscriminator(DiscriminatorMapping discriminatorMapping)
 {
 }
 public DiscriminatorInspector(DiscriminatorMapping mapping)
     : base(mapping.Columns)
 {
     this.mapping = mapping;
     propertyMappings.Map(x => x.Nullable, "NotNull");
 }