Beispiel #1
0
        SubclassMapping IIndeterminateSubclassMappingProvider.GetSubclassMapping(SubclassType type)
        {
            var mapping = new SubclassMapping(type);

            GenerateNestedSubclasses(mapping);

            attributes.SetDefault(x => x.Type, typeof(T));
            attributes.SetDefault(x => x.Name, typeof(T).AssemblyQualifiedName);
            attributes.SetDefault(x => x.DiscriminatorValue, typeof(T).Name);

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

            key.AddDefaultColumn(new ColumnMapping {
                Name = typeof(T).BaseType.Name + "_id"
            });

            attributes.SetDefault(x => x.TableName, GetDefaultTableName());
            attributes.SetDefault(x => x.Key, key);

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

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

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

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

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

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

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

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

            return(mapping.DeepClone());
        }
Beispiel #2
0
        void InitialiseDefaults(Member member)
        {
            mapping.Member = member;
            mapping.SetDefaultValue(x => x.Name, member.Name);
            mapping.SetDefaultValue(x => x.TableName, mapping.ContainingEntityType.Name + member.Name);

            mapping.Key = key = new KeyMapping();
            key.AddDefaultColumn(new ColumnMapping {
                Name = mapping.ContainingEntityType.Name + "_id"
            });

            mapping.Index = index = new IndexMapping();
            mapping.Index.As <IndexMapping>(ix =>
                                            ix.SetDefaultValue(x => x.Type, new TypeReference(KeyType)));

            if (ValueType.IsSimpleType())
            {
                // value type value (element)
                mapping.Element = element = new ElementMapping();
                element.AddDefaultColumn(new ColumnMapping {
                    Name = "Value"
                });
                element.SetDefaultValue(x => x.Type, new TypeReference(typeof(TValue)));
            }
            else
            {
                // entity value
                mapping.Relationship = manyToMany = new ManyToManyMapping();
                manyToMany.Class     = new TypeReference(ValueType);
                manyToMany.AddDefaultColumn(new ColumnMapping {
                    Name = ValueType.Name + "_id"
                });
                manyToMany.ParentType = mapping.ContainingEntityType;
                manyToMany.ChildType  = ValueType;
            }

            if (KeyType.IsSimpleType())
            {
                mapping.Index.As <IndexMapping>(ix =>
                                                ix.AddDefaultColumn(new ColumnMapping {
                    Name = "Key"
                }));
            }
            else
            {
                mapping.Index.As <IndexMapping>(ix =>
                {
                    ix.IsManyToMany = true;
                    ix.AddDefaultColumn(new ColumnMapping {
                        Name = KeyType.Name + "_id"
                    });
                });
            }
        }
        public void SetKey(Member property, ClassMappingBase classMap, ICollectionMapping mapping)
        {
            var columnName = property.DeclaringType.Name + "_id";
            var key        = new KeyMapping();

            key.ContainingEntityType = classMap.Type;
            key.AddDefaultColumn(new ColumnMapping {
                Name = columnName
            });

            mapping.SetDefaultValue(x => x.Key, key);
        }
Beispiel #4
0
        public JoinPart(string tableName)
        {
            fetch = new FetchTypeExpression <JoinPart <T> >(this, value => attributes.Set(x => x.Fetch, value));

            keyMapping = new KeyMapping {
                ContainingEntityType = typeof(T)
            };
            keyMapping.AddDefaultColumn(new ColumnMapping {
                Name = typeof(T).Name + "_id"
            });
            attributes.SetDefault(x => x.TableName, tableName);
            attributes.Set(x => x.Key, keyMapping);
        }
Beispiel #5
0
        private void SetKey(Member property, ClassMappingBase classMap, ICollectionMapping mapping)
        {
            var columnName = property.DeclaringType.Name + "_Id";

            if (classMap is ComponentMapping)
            {
                columnName = expressions.GetComponentColumnPrefix(((ComponentMapping)classMap).Member) + columnName;
            }

            var key = new KeyMapping();

            key.ContainingEntityType = classMap.Type;
            key.AddDefaultColumn(new ColumnMapping {
                Name = columnName
            });

            mapping.SetDefaultValue(x => x.Key, key);
        }
Beispiel #6
0
        protected ToManyBase(Type entity, Member member, Type type)
        {
            this.entity = entity;
            this.member = member;
            AsBag();
            access         = new AccessStrategyBuilder <T>((T)this, value => collectionAttributes.Set(x => x.Access, value));
            fetch          = new FetchTypeExpression <T>((T)this, value => collectionAttributes.Set(x => x.Fetch, value));
            optimisticLock = new OptimisticLockBuilder <T>((T)this, value => collectionAttributes.Set(x => x.OptimisticLock, value));
            cascade        = new CollectionCascadeExpression <T>((T)this, value => collectionAttributes.Set(x => x.Cascade, value));

            SetDefaultCollectionType(type);
            SetCustomCollectionType(type);

            collectionAttributes.SetDefault(x => x.Name, member.Name);

            keyMapping = new KeyMapping();
            keyMapping.AddDefaultColumn(new ColumnMapping {
                Name = entity.Name + "_id"
            });
        }