Inheritance: FluentNHibernate.MappingModel.MappingBase, INameable
        public void Should_produce_valid_hbm()
        {
            var manyToOne = new ManyToOneMapping { Name = "manyToOne" };
            var writer = new HbmManyToOneWriter();

            writer.ShouldGenerateValidOutput(manyToOne);
        }
        public void CanAddReference()
        {
            var reference = new ManyToOneMapping { Name = "parent" };
            _classMapping.AddReference(reference);

            _classMapping.References.ShouldContain(reference);
        }
        public void CanAddReference()
        {
            var reference = new ManyToOneMapping { Name = "parent" };
            compositeElementMapping.AddReference(reference);

            compositeElementMapping.References.ShouldContain(reference);
        }
        public override void ProcessManyToOne(ManyToOneMapping thisSide)
        {
            if (thisSide.OtherSide == null)
                return;

            // other side is always going to be a collection for a many-to-one mapping
            var otherSide = (ICollectionMapping)thisSide.OtherSide;

            // both sides have user-defined key columns... leave alone!
            if (otherSide.Key.Columns.HasUserDefined() && thisSide.Columns.HasUserDefined())
                return;

            if (otherSide.Key.Columns.HasUserDefined())
            {
                // only other side has user-defined columns, so we'll bring them across to this side
                thisSide.ClearColumns();
                otherSide.Key.Columns.Each(x => thisSide.AddColumn(x.Clone()));
                return;
            }

            if (otherSide.Key.Columns.HasUserDefined())
            {
                // only other side has user-defined columns, so we'll bring them across to this side
                thisSide.ClearColumns();
                otherSide.Key.Columns.Each(x => thisSide.AddColumn(x.Clone()));
                return;
            }

            // the other side doesn't have any user defined columns, so we'll use the ones from this side
            // whether they're user defined or not.
            otherSide.Key.ClearColumns();
            thisSide.Columns.Each(x => otherSide.Key.AddColumn(x.Clone()));
        }
        public void Should_not_write_the_default_access_type()
        {
            var manyToOne = new ManyToOneMapping();

            _writer.VerifyXml(manyToOne)
                .DoesntHaveAttribute("access");
        }
        public override void establish_context()
        {
            manyToOneARankedFirstToHolder = new ManyToOneMapping();
            manyToOneARankedFirstToHolder.Set(x => x.Class, Layer.Defaults, new TypeReference(typeof(Holder)));
            manyToOneARankedFirstToHolder.Set(x => x.Name, Layer.Defaults, "ARankedFirstProperty");
            manyToOneARankedFirstToHolder.ContainingEntityType = typeof(ARankedFirst);
            manyToOneARankedFirstToHolder.Member = new PropertyMember(typeof(ARankedFirst).GetProperty("ARankedFirstProperty"));

            manyToOneBRankedSecondToHolder = new ManyToOneMapping();
            manyToOneBRankedSecondToHolder.Set(x => x.Class, Layer.Defaults, new TypeReference(typeof(Holder)));
            manyToOneBRankedSecondToHolder.Set(x => x.Name, Layer.Defaults, "BRankedSecondProperty");
            manyToOneBRankedSecondToHolder.ContainingEntityType = typeof(BRankedSecond);
            manyToOneBRankedSecondToHolder.Member = new PropertyMember(typeof(BRankedSecond).GetProperty("BRankedSecondProperty"));

            var relationship = new OneToManyMapping();
            relationship.Set(x => x.Class, Layer.Defaults, new TypeReference(typeof(BRankedSecond)));
            relationship.ContainingEntityType = typeof(Holder);

            collectionMappingToBRankedSecond = CollectionMapping.Bag();
            collectionMappingToBRankedSecond.Set(x => x.ChildType, Layer.Defaults, typeof(BRankedSecond));
            collectionMappingToBRankedSecond.Set(x => x.Name, Layer.Defaults, "ColectionOfBRankedSeconds");
            collectionMappingToBRankedSecond.Set(x => x.Relationship, Layer.Defaults, relationship);
            collectionMappingToBRankedSecond.ContainingEntityType = typeof(Holder);

            visitor = new RelationshipPairingVisitor(A.Fake<PairBiDirectionalManyToManySidesDelegate>());
        }
        public void Should_write_the_specified_access_type()
        {
            var manyToOne = new ManyToOneMapping();
            manyToOne.MemberAccess = MemberAccess.Create(AccessStrategy.Field, NamingStrategy.CamelCase);

            _writer.VerifyXml(manyToOne)
                .HasAttribute("access", "field.camelcase");
        }
        public void CanAddReference()
        {
            var reference = new ManyToOneMapping();
            reference.Set(x => x.Name, Layer.Defaults, "parent");
            mapping.AddReference(reference);

            mapping.References.ShouldContain(reference);
        }
Exemple #9
0
 public void AddReference(ManyToOneMapping manyToOne)
 {
     if (References.Any(x => x.Name == manyToOne.Name))
     {
         throw new InvalidOperationException("Tried to add many-to-one '" + manyToOne.Name + "' when already added.");
     }
     AddMapping(manyToOne, MappingType.ManyToOne);
 }
        public void ShouldWriteProxyLazyAttribute()
        {
            var mapping = new ManyToOneMapping();

            mapping.Set(x => x.Lazy, Layer.Defaults, Laziness.Proxy.ToString());

            writer.VerifyXml(mapping)
                .HasAttribute("lazy", "proxy");
        }
        public void ShouldWriteProxyLazyAttribute()
        {
            var mapping = new ManyToOneMapping();

            mapping.Lazy = Laziness.Proxy.ToString();

            writer.VerifyXml(mapping)
                .HasAttribute("lazy", "proxy");
        }
        private ManyToOneMapping CreateMapping(PropertyInfo property)
        {
            var mapping = new ManyToOneMapping { PropertyInfo = property };

            mapping.SetDefaultValue(x => x.Name, property.Name);
            mapping.AddDefaultColumn(new ColumnMapping { Name = property.Name + "_id" });

            return mapping;
        }
        public void ShouldWriteColumns()
        {
            var mapping = new ManyToOneMapping();

            mapping.AddColumn(new ColumnMapping());

            writer.VerifyXml(mapping)
                .Element("column").Exists();
        }
        public void AddReference(ManyToOneMapping manyToOne)
        {
            if (references.Exists(x => x.Name == manyToOne.Name))
            {
                throw new InvalidOperationException("Tried to add many-to-one '" + manyToOne.Name + "' when already added.");
            }

            references.Add(manyToOne);
        }
        private ManyToOneMapping CreateMapping(Member property)
        {
            var mapping = new ManyToOneMapping { Member = property };

            mapping.SetDefaultValue(x => x.Name, property.Name);
            mapping.SetDefaultValue(x => x.Class, new TypeReference(property.PropertyType));
            mapping.AddDefaultColumn(new ColumnMapping { Name = property.Name + "_id" });

            return mapping;
        }
        public override void ProcessManyToOne(ManyToOneMapping thisSide)
        {
            if (thisSide.OtherSide == null)
                return;

            // other side is always going to be a collection for a many-to-one mapping
            var otherSide = (CollectionMapping)thisSide.OtherSide;

            otherSide.Key.MakeColumnsEmpty(Layer.Defaults);
            thisSide.Columns.Each(x => otherSide.Key.AddColumn(Layer.Defaults, x.Clone()));
        }
        private ManyToOneMapping CreateMapping(Member member)
        {
            var mapping = new ManyToOneMapping { Member = member };

            mapping.SetDefaultValue(x => x.Name, member.Name);
            mapping.SetDefaultValue(x => x.Class, new TypeReference(member.PropertyType));
            mapping.AddDefaultColumn(new ColumnMapping { Name = member.Name + "_id" });

            if (member.IsProperty && !member.CanWrite)
                mapping.SetDefaultValue(x => x.Access, cfg.GetAccessStrategyForReadOnlyProperty(member).ToString());

            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;
        }
        void SetDefaultAccess(Member member, ManyToOneMapping mapping)
        {
            var resolvedAccess = MemberAccessResolver.Resolve(member);

            if (resolvedAccess != Access.Property && resolvedAccess != Access.Unset)
            {
                // if it's a property or unset then we'll just let NH deal with it, otherwise
                // set the access to be whatever we determined it might be
                mapping.Set(x => x.Access, Layer.Defaults, resolvedAccess.ToString());
            }

            if (member.IsProperty && !member.CanWrite)
                mapping.Set(x => x.Access, Layer.Defaults, cfg.GetAccessStrategyForReadOnlyProperty(member).ToString());
        }
Exemple #20
0
 public bool Equals(ManyToOneMapping other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(Equals(other.attributes, attributes) &&
            other.columns.ContentEquals(columns) &&
            Equals(other.ContainingEntityType, ContainingEntityType) &&
            Equals(other.Member, Member));
 }
        public override void ProcessManyToOne(ManyToOneMapping thisSide)
        {
            if (thisSide.OtherSide == null)
                return;

            // other side is always going to be a collection for a many-to-one mapping
            var otherSide = (CollectionMapping)thisSide.OtherSide;

            if (thisSide.ContainingEntityType == otherSide.ContainingEntityType)
            {
                // special case for self-referential relationships
                otherSide.Key.MakeColumnsEmpty(Layer.Defaults);
                thisSide.Columns.Each(x => otherSide.Key.AddColumn(Layer.Defaults, x.Clone()));
            }
        }
        public override void ProcessManyToOne(ManyToOneMapping thisSide)
        {
            if (thisSide.OtherSide == null)
                return;

            // other side is always going to be a collection for a many-to-one mapping
            var otherSide = (ICollectionMapping)thisSide.OtherSide;

            if (thisSide.ContainingEntityType == otherSide.ContainingEntityType)
            {
                // special case for self-referential relationships
                if (thisSide.Columns.HasUserDefined() || otherSide.Key.Columns.HasUserDefined())
                    return; // leave alone if user defined

                otherSide.Key.ClearColumns();
                thisSide.Columns.Each(x => otherSide.Key.AddDefaultColumn(x.Clone()));
            }
        }
Exemple #23
0
 public virtual void ProcessManyToOne(ManyToOneMapping manyToOneMapping)
 {
 }
Exemple #24
0
 public virtual void Visit(ManyToOneMapping manyToOneMapping)
 {
 }
        public void Should_apply_to_many_to_one_mapping()
        {
            var propertyInfo = ReflectionHelper.GetProperty((Album a) => a.Artist);
            var manyToOneMapping = new ManyToOneMapping { PropertyInfo = propertyInfo };

            _namingConvention.ProcessManyToOne(manyToOneMapping);

            manyToOneMapping.Name.ShouldEqual(manyToOneMapping.PropertyInfo.Name);
        }
 protected ManyToOneMapping reference_with_column(string column)
 {
     var reference = new ManyToOneMapping();
     reference.AddDefaultColumn(new ColumnMapping { Name = "propertyColumn" });
     return reference;
 }
Exemple #27
0
 public void AddOrReplaceReference(ManyToOneMapping manyToOne)
 {
     AddOrReplaceMapping(manyToOne, MappingType.ManyToOne, x => x.Name == manyToOne.Name);
 }
 public void AddOrReplaceReference(ManyToOneMapping manyToOne)
 {
     references.RemoveAll(x => x.Name == manyToOne.Name);
     sequencedMappingObject.RemoveAll(x => x is ManyToOneMapping && ((ManyToOneMapping) x).Name == manyToOne.Name);
     references.Add(manyToOne);
     sequencedMappingObject.Add(manyToOne);
 }
 public override void Visit(ManyToOneMapping manyToOneMapping)
 {
     manyToOneMapping.AcceptVisitor(this);
 }
Exemple #30
0
 public void AddReference(ManyToOneMapping mapping)
 {
     manyToOnes.Add(mapping);
 }
Exemple #31
0
 public override void Visit(ManyToOneMapping manyToOneMapping)
 {
     manyToOneMapping.AcceptVisitor(this);
 }
 public void CreateDsl()
 {
     mapping = new ManyToOneMapping();
     inspector = new ManyToOneInspector(mapping);
 }
        public void AddReference(ManyToOneMapping manyToOne)
        {
            if (references.Exists(x => x.Name == manyToOne.Name))
                throw new InvalidOperationException("Tried to add many-to-one '" + manyToOne.Name + "' when already added.");

            references.Add(manyToOne);
        }
 public virtual void ProcessManyToOne(ManyToOneMapping manyToOneMapping)
 {
 }
 public virtual void Visit(ManyToOneMapping manyToOneMapping)
 {
 }
 public void AddOrReplaceReference(ManyToOneMapping manyToOne)
 {
     references.RemoveAll(x => x.Name == manyToOne.Name);
     references.Add(manyToOne);
 }
 public override void ProcessManyToOne(ManyToOneMapping manyToOneMapping)
 {
     references.Add(manyToOneMapping);
 }
Exemple #38
0
 public void AddReference(ManyToOneMapping manyToOne)
 {
     mappedMembers.AddReference(manyToOne);
 }
 public void AddOrReplaceReference(ManyToOneMapping manyToOne)
 {
     references.RemoveAll(x => x.Name == manyToOne.Name);
     references.Add(manyToOne);
 }
 public ManyToOneInspector(ManyToOneMapping mapping)
 {
     this.mapping = mapping;
     propertyMappings.Map(x => x.LazyLoad, x => x.Lazy);
     propertyMappings.Map(x => x.Nullable, "NotNull");
 }