コード例 #1
0
 /// <summary>
 /// Sets the column name
 /// </summary>
 /// <param name="keyColumnName"></param>
 public void Column(string keyColumnName)
 {
     mapping.AddColumn(new ColumnMapping(sharedColumnAttributes)
     {
         Name = keyColumnName
     });
 }
コード例 #2
0
ファイル: SubclassMap.cs プロジェクト: akhuang/NHibernateTest
        SubclassMapping IIndeterminateSubclassMappingProvider.GetSubclassMapping(SubclassType type)
        {
            var mapping = new SubclassMapping(type);

            GenerateNestedSubclasses(mapping);

            attributes.Set("Type", Layer.Defaults, typeof(T));
            attributes.Set("Name", Layer.Defaults, typeof(T).AssemblyQualifiedName);
            attributes.Set("DiscriminatorValue", Layer.Defaults, typeof(T).Name);

            // TODO: un-hardcode this
            var key = new KeyMapping();

            key.AddColumn(Layer.Defaults, new ColumnMapping(typeof(T).BaseType.Name + "_id"));

            attributes.Set("TableName", Layer.Defaults, GetDefaultTableName());
            attributes.Set("Key", Layer.Defaults, key);

            // TODO: this is nasty, we should find a better way
            mapping.OverrideAttributes(attributes.Clone());

            foreach (var join in joins)
            {
                mapping.AddJoin(join);
            }

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

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

            foreach (var oneToOne in providers.OneToOnes)
            {
                mapping.AddOneToOne(oneToOne.GetOneToOneMapping());
            }

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

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

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

            return(mapping.DeepClone());
        }
コード例 #3
0
        public void ShouldWriteColumns()
        {
            var mapping = new KeyMapping();

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

            writer.VerifyXml(mapping)
            .Element("column").Exists();
        }
コード例 #4
0
        public void Column(string columnName)
        {
            var originalColumn = mapping.Columns.FirstOrDefault();
            var column         = originalColumn == null ? new ColumnMapping() : originalColumn.Clone();

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

            mapping.AddColumn(Layer.Conventions, column);
        }
コード例 #5
0
        public void ShouldWriteColumns()
        {
            var mapping = new KeyMapping();

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

            writer.VerifyXml(mapping)
            .Element("column").Exists();
        }
コード例 #6
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);
        }
コード例 #7
0
        public void Column(string columnName)
        {
            if (mapping.Columns.UserDefined.Count() > 0)
            {
                return;
            }

            var originalColumn = mapping.Columns.FirstOrDefault();
            var column         = originalColumn == null ? new ColumnMapping() : ColumnMapping.BaseOn(originalColumn);

            column.Name = columnName;

            mapping.ClearColumns();
            mapping.AddColumn(column);
        }
コード例 #8
0
 public void ColumnsCollectionHasSameCountAsMapping()
 {
     mapping.AddColumn(new ColumnMapping());
     inspector.Columns.Count().ShouldEqual(1);
 }
コード例 #9
0
        SubclassMapping IIndeterminateSubclassMappingProvider.GetSubclassMapping(SubclassType type)
        {
            var mapping = new SubclassMapping(type);

            GenerateNestedSubclasses(mapping);

            attributes.Set("Type", Layer.Defaults, typeof(T));
            attributes.Set("Name", Layer.Defaults, typeof(T).AssemblyQualifiedName);
            attributes.Set("DiscriminatorValue", Layer.Defaults, typeof(T).Name);

            // TODO: un-hardcode this
            Type baseType = typeof(T).BaseType
                            ?? attributes.Get("Extends") as Type;

            if (baseType != null)
            {
                var key = new KeyMapping();
                key.AddColumn(Layer.Defaults, new ColumnMapping(baseType.Name + "_id"));
                attributes.Set("Key", Layer.Defaults, key);
            }

            attributes.Set("TableName", Layer.Defaults, GetDefaultTableName());

            // TODO: this is nasty, we should find a better way
            mapping.OverrideAttributes(attributes.Clone());

            foreach (var join in joins)
            {
                mapping.AddJoin(join);
            }

            foreach (var provider in providers.OrderedProviders)
            {
                var mappingProviderObj = provider.Item2;
                switch (provider.Item1)
                {
                case MappingProviderStore.ProviderType.Property:
                    mapping.AddProperty(((IPropertyMappingProvider)mappingProviderObj).GetPropertyMapping());
                    break;

                case MappingProviderStore.ProviderType.Component:
                    mapping.AddComponent(((IComponentMappingProvider)mappingProviderObj).GetComponentMapping());
                    break;

                case MappingProviderStore.ProviderType.OneToOne:
                    mapping.AddOneToOne(((IOneToOneMappingProvider)mappingProviderObj).GetOneToOneMapping());
                    break;

                case MappingProviderStore.ProviderType.Collection:
                    mapping.AddCollection(((ICollectionMappingProvider)mappingProviderObj).GetCollectionMapping());
                    break;

                case MappingProviderStore.ProviderType.ManyToOne:
                    mapping.AddReference(((IManyToOneMappingProvider)mappingProviderObj).GetManyToOneMapping());
                    break;

                case MappingProviderStore.ProviderType.Any:
                    mapping.AddAny(((IAnyMappingProvider)mappingProviderObj).GetAnyMapping());
                    break;

                case MappingProviderStore.ProviderType.Subclass:
                case MappingProviderStore.ProviderType.Filter:
                case MappingProviderStore.ProviderType.StoredProcedure:
                case MappingProviderStore.ProviderType.Join:
                case MappingProviderStore.ProviderType.Identity:
                case MappingProviderStore.ProviderType.CompositeId:
                case MappingProviderStore.ProviderType.NaturalId:
                case MappingProviderStore.ProviderType.Version:
                case MappingProviderStore.ProviderType.Discriminator:
                case MappingProviderStore.ProviderType.Tupilizer:
                default:
                    throw new Exception("Internal Error");
                }
            }

            return(mapping.DeepClone());
        }