コード例 #1
0
        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);
        }
コード例 #2
0
ファイル: AutoMapper.cs プロジェクト: oblivious/Oblivious
        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);
            }
        }
コード例 #3
0
        public KeyPropertyPart ColumnName(string columnName)
        {
            var column = new ColumnMapping();
            column.Set(x => x.Name, Layer.UserSupplied, columnName);

            mapping.AddColumn(column);
            return this;
        }
コード例 #4
0
ファイル: IdentityStep.cs プロジェクト: umittal/MunimJi
        public void Map(ClassMappingBase classMap, Member member)
        {
            if (!(classMap is ClassMapping)) {
                return;
            }

            var identity = ((ClassMapping) classMap).Id;
            if (identity == null) {
                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);

                identity = idMapping;
            }
            else {
                if (identity is IdMapping) {
                    var idMapping = identity as IdMapping;
                    var compositeId = new CompositeIdMapping {ContainingEntityType = classMap.Type};

                    var idKeyPropertyMapping = GetKeyPropertyMapping(classMap.Type, idMapping.Name,
                                                                     idMapping.Type.GetUnderlyingSystemType());

                    var keyPropertyMapping = GetKeyPropertyMapping(classMap.Type, member.Name,
                                                                   member.PropertyType);

                    compositeId.AddKey(idKeyPropertyMapping);
                    compositeId.AddKey(keyPropertyMapping);

                    identity = compositeId;
                }
                else if (identity is CompositeIdMapping) {
                    var compositeId = identity as CompositeIdMapping;

                    var keyPropertyMapping = GetKeyPropertyMapping(classMap.Type, member.Name,
                                                                   member.PropertyType);

                    compositeId.AddKey(keyPropertyMapping);

                    identity = compositeId;
                }
                else {
                    throw new NotImplementedException(
                        string.Format("Mayank: Fluent nhibernate not exended to support type '{0}'",
                                      identity.GetType().Name));
                }
            }

            ((ClassMapping) classMap).Set(x => x.Id, Layer.Defaults, identity);
        }
コード例 #5
0
        private static void SetKey(Member property, ClassMappingBase classMap, CollectionMapping mapping)
        {
            var ColumnName = "Id_"+property.DeclaringType.Name;
            var ColumnMapping = new ColumnMapping();
            ColumnMapping.Set(x => x.Name, Layer.Defaults, ColumnName);

            var Key = new KeyMapping {ContainingEntityType = classMap.Type};
            Key.AddColumn(Layer.Defaults, ColumnMapping);

            mapping.Set(x => x.Key, Layer.Defaults, Key);
        }
        static ICollectionRelationshipMapping CreateManyToMany(Member member, Type parentType, Type childType)
        {
            var columnMapping = new ColumnMapping();
            columnMapping.Set(x => x.Name, Layer.Defaults, childType.Name + "Id");

            var mapping = new ManyToManyMapping { ContainingEntityType = parentType };
            mapping.Set(x => x.Class, Layer.Defaults, new TypeReference(childType));
            mapping.Set(x => x.ParentType, Layer.Defaults, parentType);
            mapping.Set(x => x.ChildType, Layer.Defaults, childType);
            mapping.AddColumn(Layer.Defaults, columnMapping);

            return mapping;
        }
コード例 #7
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);
        }
コード例 #8
0
        private static ICollectionRelationshipMapping CreateManyToMany(Member member, Type parentType, Type childType)
        {
            var ColumnMapping = new ColumnMapping();
            ColumnMapping.Set(x => x.Name, Layer.Defaults, "Id_" + childType.Name);

            var Mapping = new ManyToManyMapping {ContainingEntityType = parentType};
            Mapping.Set(x => x.Class, Layer.Defaults, new FluentNHibernate.MappingModel.TypeReference(childType));
            Mapping.Set(x => x.ParentType, Layer.Defaults, parentType);
            Mapping.Set(x => x.ChildType, Layer.Defaults, childType);
            Mapping.AddColumn(Layer.Defaults, ColumnMapping);

            return Mapping;
        }
コード例 #9
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;
        }
コード例 #10
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;
        }
コード例 #11
0
        public 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);
        }
コード例 #12
0
ファイル: IdentityStep.cs プロジェクト: oblivious/Oblivious
        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);        
        }
コード例 #13
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;
        }
コード例 #14
0
 public override void ProcessColumn(ColumnMapping columnMapping)
 {
     if (prefixes.Any())
         columnMapping.Set(x => x.Name, Layer.UserSupplied, GetPrefix() + columnMapping.Name);
 }
コード例 #15
0
ファイル: IdentityStep.cs プロジェクト: umittal/MunimJi
 private static KeyPropertyMapping GetKeyPropertyMapping(Type entityType, string name, Type type)
 {
     var keyPropertyMapping = new KeyPropertyMapping {ContainingEntityType = entityType};
     keyPropertyMapping.Set(x => x.Name, Layer.Defaults, name);
     keyPropertyMapping.Set(x => x.Type, Layer.Defaults, new TypeReference(type));
     var columnMapping = new ColumnMapping();
     columnMapping.Set(x => x.Name, Layer.Defaults, name);
     keyPropertyMapping.AddColumn(columnMapping);
     return keyPropertyMapping;
 }