当前位置: 首页>>代码示例>>C#>>正文


C# ClassMappingBase.AddSubclass方法代码示例

本文整理汇总了C#中FluentNHibernate.MappingModel.ClassBased.ClassMappingBase.AddSubclass方法的典型用法代码示例。如果您正苦于以下问题:C# ClassMappingBase.AddSubclass方法的具体用法?C# ClassMappingBase.AddSubclass怎么用?C# ClassMappingBase.AddSubclass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FluentNHibernate.MappingModel.ClassBased.ClassMappingBase的用法示例。


在下文中一共展示了ClassMappingBase.AddSubclass方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MapInheritanceTree

        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);
            }
        }
开发者ID:akhuang,项目名称:NHibernateTest,代码行数:59,代码来源:AutoMapper.cs

示例2: MapInheritanceTree

        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);
            }
        }
开发者ID:Kaidanov,项目名称:fluent-nhibernate,代码行数:51,代码来源:AutoMapper.cs

示例3: MapInheritanceTree

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

                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);
            }
        }
开发者ID:roelofb,项目名称:fluent-nhibernate,代码行数:50,代码来源:AutoMapper.cs

示例4: MapInheritanceTree

        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);
            }
        }
开发者ID:erikojebo,项目名称:fluent-nhibernate,代码行数:44,代码来源:AutoMapper.cs


注:本文中的FluentNHibernate.MappingModel.ClassBased.ClassMappingBase.AddSubclass方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。