コード例 #1
0
        protected virtual CompositeIdentityPart <T> KeyReference(Member member, IEnumerable <string> columnNames, Action <KeyManyToOnePart> customMapping)
        {
            onMemberMapped(member);

            var key = new KeyManyToOneMapping
            {
                ContainingEntityType = typeof(T)
            };

            key.Set(x => x.Name, Layer.Defaults, member.Name);
            key.Set(x => x.Class, Layer.Defaults, new TypeReference(member.PropertyType));

            foreach (var column in columnNames)
            {
                var columnMapping = new ColumnMapping();
                columnMapping.Set(x => x.Name, Layer.Defaults, column);
                key.AddColumn(columnMapping);
            }

            var keyPart = new KeyManyToOnePart(key);

            if (customMapping != null)
            {
                customMapping(keyPart);
            }

            keys.Add(key);

            return(this);
        }
コード例 #2
0
        ColumnMapping CreateColumn(string column)
        {
            var columnMapping = new ColumnMapping(columnAttributes.Clone());

            columnMapping.Set(x => x.Name, Layer.Defaults, column);
            return(columnMapping);
        }
コード例 #3
0
 public override void ProcessColumn(ColumnMapping columnMapping)
 {
     if (prefixes.Any())
     {
         columnMapping.Set(x => x.Name, Layer.UserSupplied, GetPrefix() + columnMapping.Name);
     }
 }
コード例 #4
0
        protected virtual CompositeIdentityPart <T> KeyProperty(Member member, string columnName, Action <KeyPropertyPart> customMapping)
        {
            var type = member.PropertyType;

            if (type.IsEnum)
            {
                type = typeof(GenericEnumMapper <>).MakeGenericType(type);
            }

            var key = new KeyPropertyMapping
            {
                ContainingEntityType = typeof(T)
            };

            key.Set(x => x.Name, Layer.Defaults, member.Name);
            key.Set(x => x.Type, Layer.Defaults, new TypeReference(type));

            if (customMapping != null)
            {
                var part = new KeyPropertyPart(key);
                customMapping(part);
            }

            if (!string.IsNullOrEmpty(columnName))
            {
                var columnMapping = new ColumnMapping();
                columnMapping.Set(x => x.Name, Layer.Defaults, columnName);
                key.AddColumn(columnMapping);
            }

            keys.Add(key);

            return(this);
        }
コード例 #5
0
        /// <summary>
        /// Specifies the column name for the index or key of the dictionary.
        /// </summary>
        /// <param name="indexColumnName">Column name</param>
        public void Column(string indexColumnName)
        {
            var column = new ColumnMapping(sharedColumnAttributes);

            column.Set(x => x.Name, Layer.UserSupplied, indexColumnName);
            mapping.AddColumn(Layer.UserSupplied, column);
        }
コード例 #6
0
        PropertyMapping IPropertyMappingProvider.GetPropertyMapping()
        {
            var mapping = new PropertyMapping(attributes.Clone())
            {
                ContainingEntityType = parentType,
                Member = member
            };

            if (columns.Count() == 0 && !mapping.IsSpecified("Formula"))
            {
                var columnMapping = new ColumnMapping(columnAttributes.Clone());
                columnMapping.Set(x => x.Name, Layer.Defaults, member.Name);
                mapping.AddColumn(Layer.Defaults, columnMapping);
            }

            foreach (var column in columns)
            {
                mapping.AddColumn(Layer.UserSupplied, column);
            }

            foreach (var column in mapping.Columns)
            {
                if (member.PropertyType.IsNullable() && member.PropertyType.IsEnum())
                {
                    column.Set(x => x.NotNull, Layer.Defaults, false);
                }

                column.MergeAttributes(columnAttributes);
            }

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

            return(mapping);
        }
コード例 #7
0
ファイル: VersionStep.cs プロジェクト: akhuang/NHibernateTest
        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);
        }
コード例 #8
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;
                var             tempSubClassMap = mapping as SubclassMapping;
                if (!tempIsNull && tempMapping.IsUnionSubclass || tempSubClassMap != null && tempSubClassMap.SubclassType == SubclassType.UnionSubclass)
                {
                    subclassMapping = new SubclassMapping(SubclassType.UnionSubclass);
                    subclassMapping.Set(x => x.Type, Layer.Defaults, inheritedClass.Type);
                }
                else if (isDiscriminated || tempSubClassMap != null && tempSubClassMap.SubclassType == SubclassType.Subclass)
                {
                    subclassMapping = new SubclassMapping(SubclassType.Subclass);
                    subclassMapping.Set(x => x.Type, Layer.Defaults, inheritedClass.Type);
                }
                else
                {
                    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);
                }

                // 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);
            }
        }
コード例 #9
0
        public TParent Add(string name)
        {
            var mapping = new ColumnMapping();

            mapping.Set(x => x.Name, Layer.UserSupplied, name);
            columns.Add(mapping);
            return(parent);
        }
コード例 #10
0
        public KeyPropertyPart ColumnName(string columnName)
        {
            var column = new ColumnMapping();

            column.Set(x => x.Name, Layer.UserSupplied, columnName);

            mapping.AddColumn(column);
            return(this);
        }
コード例 #11
0
        JoinMapping IJoinMappingProvider.GetJoinMapping()
        {
            var mapping = new JoinMapping(attributes.Clone())
            {
                ContainingEntityType = typeof(T)
            };

            if (columns.Count == 0)
            {
                var columnMapping = new ColumnMapping();
                columnMapping.Set(x => x.Name, Layer.Defaults, typeof(T).Name + "_id");
                mapping.Key.AddColumn(Layer.Defaults, columnMapping);
            }
            else
            {
                foreach (var column in columns)
                {
                    var columnMapping = new ColumnMapping();
                    columnMapping.Set(x => x.Name, Layer.Defaults, column);
                    mapping.Key.AddColumn(Layer.UserSupplied, columnMapping);
                }
            }

            foreach (var property in providers.Properties)
            {
                mapping.AddProperty(property.GetPropertyMapping());
            }

            foreach (var component in providers.Components)
            {
                mapping.AddComponent(component.GetComponentMapping());
            }

            foreach (var reference in providers.References)
            {
                mapping.AddReference(reference.GetManyToOneMapping());
            }

            foreach (var any in providers.Anys)
            {
                mapping.AddAny(any.GetAnyMapping());
            }

            foreach (var collection in providers.Collections)
            {
                mapping.AddCollection(collection.GetCollectionMapping());
            }

            foreach (var storedProcedure in providers.StoredProcedures)
            {
                mapping.AddStoredProcedure(storedProcedure.GetStoredProcedureMapping());
            }

            return(mapping);
        }
コード例 #12
0
        public TParent Add(string columnName, Action <ColumnPart> customColumnMapping)
        {
            var mapping = new ColumnMapping();

            mapping.Set(x => x.Name, Layer.UserSupplied, columnName);
            var part = new ColumnPart(mapping);

            customColumnMapping(part);
            columns.Add(mapping);
            return(parent);
        }
コード例 #13
0
 void ICollectionInstance.AsList()
 {
     mapping.Collection = Collection.List;
     if (mapping.Index == null)
     {
         var indexMapping  = new IndexMapping();
         var columnMapping = new ColumnMapping();
         columnMapping.Set(x => x.Name, Layer.Defaults, "Index");
         indexMapping.AddColumn(Layer.Defaults, columnMapping);
         mapping.Set(x => x.Index, Layer.Defaults, indexMapping);
     }
     ;
 }
コード例 #14
0
        /// <summary>
        /// Use a list collection with an index
        /// </summary>
        /// <param name="customIndexMapping">Index mapping</param>
        public T AsList(Action <ListIndexPart> customIndexMapping)
        {
            collectionBuilder = attrs => CollectionMapping.List(attrs);
            CreateListIndexMapping(customIndexMapping);

            if (indexMapping.Columns.IsEmpty())
            {
                var columnMapping = new ColumnMapping();
                columnMapping.Set(x => x.Name, Layer.Defaults, "Index");
                indexMapping.AddColumn(Layer.Defaults, columnMapping);
            }

            return((T)this);
        }
コード例 #15
0
ファイル: AnyPart.cs プロジェクト: akhuang/NHibernateTest
        AnyMapping IAnyMappingProvider.GetAnyMapping()
        {
            var mapping = new AnyMapping(attributes.Clone());

            if (typeColumns.Count() == 0)
            {
                throw new InvalidOperationException("<any> mapping is not valid without specifying an Entity Type Column");
            }
            if (identifierColumns.Count() == 0)
            {
                throw new InvalidOperationException("<any> mapping is not valid without specifying an Entity Identifier Column");
            }
            if (!idTypeSet)
            {
                throw new InvalidOperationException("<any> mapping is not valid without specifying an IdType");
            }

            mapping.ContainingEntityType = entity;

            mapping.Set(x => x.Name, Layer.Defaults, member.Name);

            if (!mapping.IsSpecified("MetaType"))
            {
                mapping.Set(x => x.MetaType, Layer.Defaults, new TypeReference(member.PropertyType));
            }

            if (metaValues.Count() > 0)
            {
                metaValues.Each(mapping.AddMetaValue);
                mapping.Set(x => x.MetaType, Layer.Defaults, new TypeReference(typeof(string)));
            }

            foreach (var column in typeColumns)
            {
                var columnMapping = new ColumnMapping();
                columnMapping.Set(x => x.Name, Layer.Defaults, column);
                mapping.AddTypeColumn(Layer.UserSupplied, columnMapping);
            }


            foreach (var column in identifierColumns)
            {
                var columnMapping = new ColumnMapping();
                columnMapping.Set(x => x.Name, Layer.Defaults, column);
                mapping.AddIdentifierColumn(Layer.UserSupplied, columnMapping);
            }

            return(mapping);
        }
コード例 #16
0
        protected virtual NaturalIdPart <T> Property(Member member, string columnName)
        {
            var key = new PropertyMapping();

            key.Set(x => x.Name, Layer.Defaults, member.Name);
            key.Set(x => x.Type, Layer.Defaults, new TypeReference(member.PropertyType));
            var columnMapping = new ColumnMapping();

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

            properties.Add(key);

            return(this);
        }
コード例 #17
0
        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);
        }
コード例 #18
0
        static 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);
        }
コード例 #19
0
ファイル: IndexPart.cs プロジェクト: akhuang/NHibernateTest
        public IndexMapping GetIndexMapping()
        {
            var mapping = new IndexMapping(attributes.Clone());

            mapping.ContainingEntityType = entity;

            columns.Each(name =>
            {
                var columnMapping = new ColumnMapping();
                columnMapping.Set(x => x.Name, Layer.Defaults, name);
                mapping.AddColumn(Layer.UserSupplied, columnMapping);
            });

            return(mapping);
        }
コード例 #20
0
        /// <summary>
        /// Make this collection index
        /// </summary>
        /// <typeparam name="TIndex">Index type</typeparam>
        /// <param name="indexColumn">Index column</param>
        /// <param name="customIndexMapping">Index mapping</param>
        public T AsIndexedCollection <TIndex>(string indexColumn, Action <IndexPart> customIndexMapping)
        {
            CreateIndexMapping(customIndexMapping);

            indexMapping.Set(x => x.Type, Layer.Defaults, new TypeReference(typeof(TIndex)));

            if (indexMapping.Columns.IsEmpty())
            {
                var columnMapping = new ColumnMapping();
                columnMapping.Set(x => x.Name, Layer.Defaults, indexColumn);
                indexMapping.AddColumn(Layer.Defaults, columnMapping);
            }

            return((T)this);
        }
コード例 #21
0
        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);
        }
コード例 #22
0
        DiscriminatorMapping IDiscriminatorMappingProvider.GetDiscriminatorMapping()
        {
            var mapping = new DiscriminatorMapping(attributes.Clone())
            {
                ContainingEntityType = entity,
            };

            mapping.Set(x => x.Type, Layer.Defaults, discriminatorValueType);

            var columnMapping = new ColumnMapping(columnAttributes.Clone());

            columnMapping.Set(x => x.Name, Layer.Defaults, columnName);
            mapping.AddColumn(Layer.Defaults, columnMapping);

            return(mapping);
        }
コード例 #23
0
        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);
        }
コード例 #24
0
        protected virtual NaturalIdPart <T> Reference(Member member, string columnName)
        {
            var key = new ManyToOneMapping
            {
                ContainingEntityType = typeof(T)
            };

            key.Set(x => x.Name, Layer.Defaults, member.Name);
            key.Set(x => x.Class, Layer.Defaults, new TypeReference(member.PropertyType));
            var columnMapping = new ColumnMapping();

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

            manyToOnes.Add(key);

            return(this);
        }
コード例 #25
0
        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);
        }
コード例 #26
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);
        }
コード例 #27
0
        IdMapping IIdentityMappingProvider.GetIdentityMapping()
        {
            var mapping = new IdMapping(attributes.Clone())
            {
                ContainingEntityType = entityType
            };

            if (columns.Count > 0)
            {
                foreach (var column in columns)
                {
                    var columnMapping = new ColumnMapping(columnAttributes.Clone());
                    columnMapping.Set(x => x.Name, Layer.Defaults, column);
                    mapping.AddColumn(Layer.UserSupplied, columnMapping);
                }
            }
            else if (HasNameSpecified)
            {
                var columnMapping = new ColumnMapping(columnAttributes.Clone());
                columnMapping.Set(x => x.Name, Layer.Defaults, name);
                mapping.AddColumn(Layer.Defaults, columnMapping);
            }

            if (member != null)
            {
                mapping.Set(x => x.Name, Layer.Defaults, name);
            }

            mapping.Set(x => x.Type, Layer.Defaults, new TypeReference(identityType));

            if (GeneratedBy.IsDirty)
            {
                mapping.Set(x => x.Generator, Layer.UserSupplied, GeneratedBy.GetGeneratorMapping());
            }

            return(mapping);
        }
コード例 #28
0
ファイル: VersionPart.cs プロジェクト: akhuang/NHibernateTest
        VersionMapping IVersionMappingProvider.GetVersionMapping()
        {
            var mapping = new VersionMapping(attributes.Clone())
            {
                ContainingEntityType = entity
            };

            mapping.Set(x => x.Name, Layer.Defaults, member.Name);
            mapping.Set(x => x.Type, Layer.Defaults, member.PropertyType == typeof(DateTime) ? new TypeReference("timestamp") : new TypeReference(member.PropertyType));

            var defaultColumnMapping = new ColumnMapping(columnAttributes.Clone());

            defaultColumnMapping.Set(x => x.Name, Layer.Defaults, member.Name);
            mapping.AddColumn(Layer.Defaults, defaultColumnMapping);

            columns.ForEach(column =>
            {
                var columnMapping = new ColumnMapping(columnAttributes.Clone());
                columnMapping.Set(x => x.Name, Layer.Defaults, column);
                mapping.AddColumn(Layer.UserSupplied, columnMapping);
            });

            return(mapping);
        }
コード例 #29
0
 /// <summary>
 /// Specify the column name
 /// </summary>
 /// <param name="columnName">Column name</param>
 public ColumnPart Name(string columnName)
 {
     columnMapping.Set(x => x.Name, Layer.UserSupplied, columnName);
     return(this);
 }
コード例 #30
0
 public new void Length(int length)
 {
     mapping.Set(x => x.Length, Layer.Conventions, length);
 }