예제 #1
0
        /// <summary>
        /// Gets the CompositeId of the @class if it exists
        /// </summary>
        /// <param name="theClass"></param>
        /// <returns></returns>
        public static compositeid CompositeId(this @class theClass)
        {
            if (theClass.Item != null && theClass.Item is compositeid)
            {
                return((compositeid)theClass.Item);
            }

            return(null);
        }
예제 #2
0
        /// <summary>
        /// Gets the Version of the @class if it exists
        /// </summary>
        /// <param name="theClass"></param>
        /// <returns></returns>
        public static version Version(this @class theClass)
        {
            if (theClass.Item1 != null && theClass.Item1 is version)
            {
                return((version)theClass.Item1);
            }

            return(null);
        }
        public static void AddClass(this hibernatemapping hm, @class @class)
        {
            if (hm.Items == null)
                hm.Items = new object[0];

            object[] items = hm.Items;
            Array.Resize(ref items, hm.Items.Length + 1);
            items[items.Length - 1] = @class;
            hm.Items = items;
        }
        public static string ResolveShortClassName(@class hClass, hibernatemapping hm)
        {
            // remove everything after the comma if there is one.
            int indexOfComma = Math.Max(hClass.name.IndexOf(","), hClass.name.Length);
            string className = hClass.name.Substring(0, indexOfComma);

            // If the classname is not fully qualified, return it.
            if (className.Contains(".") == false) return className;

            return className.Substring(className.LastIndexOf(".") + 1);
        }
예제 #5
0
        public static void AddItem(this @class theClass, object property)
        {
            if (theClass.Items == null)
            {
                theClass.Items = new object[0];
            }

            object[] items = theClass.Items;
            Array.Resize(ref items, theClass.Items.Length + 1);
            items[items.Length - 1] = property;
            theClass.Items          = items;
        }
예제 #6
0
        public static void AddComponent(this @class theClass, component component)
        {
            if (theClass.Items == null)
            {
                theClass.Items = new object[0];
            }

            object[] items = theClass.Items;
            Array.Resize(ref items, theClass.Items.Length + 1);
            items[items.Length - 1] = component;
            theClass.Items          = items;
        }
예제 #7
0
        public static void AddSubClass(this @class theClass, @class subClass)
        {
            if (theClass.Items1 == null)
            {
                theClass.Items1 = new object[0];
            }

            object[] items = theClass.Items1;
            Array.Resize(ref items, theClass.Items1.Length + 1);
            items[items.Length - 1] = subClass;
            theClass.Items1         = items;
        }
예제 #8
0
        public static void AddItem1 <T>(this @class theClass, T property) where T : class
        {
            if (theClass.Items1 == null)
            {
                theClass.Items1 = new object[0];
            }

            object[] items = theClass.Items1;
            Array.Resize(ref items, theClass.Items1.Length + 1);
            items[items.Length - 1] = property;
            theClass.Items1         = items;
        }
예제 #9
0
 /// <summary>
 /// Gets a collection of union-subclasses in the @class
 /// </summary>
 /// <param name="theClass"></param>
 /// <returns></returns>
 public static IEnumerable <unionsubclass> UnionSubClasses(this @class theClass)
 {
     if (theClass.Items1 == null)
     {
         yield break;
     }
     foreach (var item in theClass.Items1)
     {
         if (item is unionsubclass)
         {
             yield return(item as unionsubclass);
         }
     }
 }
예제 #10
0
 /// <summary>
 /// Gets a collection of joined-subclasses in the @class
 /// </summary>
 /// <param name="theClass"></param>
 /// <returns></returns>
 public static IEnumerable <joinedsubclass> JoinedSubClasses(this @class theClass)
 {
     if (theClass.Items1 == null)
     {
         yield break;
     }
     foreach (var item in theClass.Items1)
     {
         if (item is joinedsubclass)
         {
             yield return(item as joinedsubclass);
         }
     }
 }
예제 #11
0
 /// <summary>
 /// Gets a collection of properties in the @class
 /// </summary>
 /// <param name="theClass"></param>
 /// <returns></returns>
 public static IEnumerable <property> Properties(this @class theClass)
 {
     if (theClass.Items == null)
     {
         yield break;
     }
     foreach (var item in theClass.Items)
     {
         if (item is property)
         {
             yield return(item as property);
         }
     }
 }
예제 #12
0
 /// <summary>
 /// Gets a collection of ManyToOnes in the @class
 /// </summary>
 /// <param name="theClass"></param>
 /// <returns></returns>
 public static IEnumerable <manytoone> ManyToOnes(this @class theClass)
 {
     if (theClass.Items == null)
     {
         yield break;
     }
     foreach (var item in theClass.Items)
     {
         if (item is manytoone)
         {
             yield return(item as manytoone);
         }
     }
 }
예제 #13
0
 /// <summary>
 /// Gets a collection of Sets in the @class
 /// </summary>
 /// <param name="theClass"></param>
 /// <returns></returns>
 public static IEnumerable <set> Sets(this @class theClass)
 {
     if (theClass.Items == null)
     {
         yield break;
     }
     foreach (var item in theClass.Items)
     {
         if (item is set)
         {
             yield return(item as set);
         }
     }
 }
예제 #14
0
 /// <summary>
 /// Gets a collection of Components in the @class
 /// </summary>
 /// <param name="theClass"></param>
 /// <returns></returns>
 public static IEnumerable <component> Components(this @class theClass)
 {
     if (theClass.Items == null)
     {
         yield break;
     }
     foreach (var item in theClass.Items)
     {
         if (item is component)
         {
             yield return(item as component);
         }
     }
 }
예제 #15
0
 /// <summary>
 /// Gets a collection of Maps in the @class
 /// </summary>
 /// <param name="theClass"></param>
 /// <returns></returns>
 public static IEnumerable <map> Maps(this @class theClass)
 {
     if (theClass.Items == null)
     {
         yield break;
     }
     foreach (var item in theClass.Items)
     {
         if (item is map)
         {
             yield return(item as map);
         }
     }
 }
예제 #16
0
 /// <summary>
 /// Gets a collection of Bags in the @class
 /// </summary>
 /// <param name="theClass"></param>
 /// <returns></returns>
 public static IEnumerable <bag> Bags(this @class theClass)
 {
     if (theClass.Items == null)
     {
         yield break;
     }
     foreach (var item in theClass.Items)
     {
         if (item is bag)
         {
             yield return(item as bag);
         }
     }
 }
예제 #17
0
 /// <summary>
 /// Gets a collection of PrimitiveArrays in the @class
 /// </summary>
 /// <param name="theClass"></param>
 /// <returns></returns>
 public static IEnumerable <primitivearray> PrimitiveArrays(this @class theClass)
 {
     if (theClass.Items == null)
     {
         yield break;
     }
     foreach (var item in theClass.Items)
     {
         if (item is primitivearray)
         {
             yield return(item as primitivearray);
         }
     }
 }
예제 #18
0
 /// <summary>
 /// Gets a collection of Anys in the @class
 /// </summary>
 /// <param name="theClass"></param>
 /// <returns></returns>
 public static IEnumerable <any> Anys(this @class theClass)
 {
     if (theClass.Items == null)
     {
         yield break;
     }
     foreach (var item in theClass.Items)
     {
         if (item is any)
         {
             yield return(item as any);
         }
     }
 }
        public static string ResolveFullClassName(@class hClass, hibernatemapping hm)
        {
            // remove everything after the comma if there is one.
            int indexOfComma = Math.Max(hClass.name.IndexOf(","), hClass.name.Length);
            string className = hClass.name.Substring(0, indexOfComma);

            // If there is no default namespace specified, return the classname
            if (string.IsNullOrEmpty(hm.@namespace))
            {
                return className;
            }

            // If the classname is already fully qualified, return it.
            if (className.Contains(".")) return className;

            // Otherwise prepend the default namespace
            return hm.@namespace + "." + className;
        }
예제 #20
0
        private void ProcessInheritance(Entity entity, @class newClass)
        {
            EntityImpl.InheritanceType inheritanceType = EntityImpl.DetermineInheritanceTypeWithChildren(entity);

            switch (inheritanceType)
            {
                case EntityImpl.InheritanceType.None:
                case EntityImpl.InheritanceType.TablePerConcreteClass:
                    // Table per concrete class doesn't need special treatment.
                    break;
                case EntityImpl.InheritanceType.TablePerClassHierarchy:
                    // All child entities are mapped to the same table as the parent.
                    ProcessEntityTablePerClassHierarchy(entity, newClass);
                    break;
                case EntityImpl.InheritanceType.TablePerSubClass:
                    ProcessEntityTablePerSubClass(entity, newClass);
                    break;
                case EntityImpl.InheritanceType.Unsupported:
                    throw new Exception("An unsupported inheritance structure was detected. "
                                        + "We only support Table Per Class Hierarchy, Table Per Sub Class, and Table Per Concrete Class. "
                                        + "See the NHibernate documentation for more details.");
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
예제 #21
0
        private void ProcessEntityTablePerSubClass(Entity entity, @class classNode)
        {
            foreach (var childEntity in entity.Children)
            {
                var mappedTable = childEntity.MappedTables().First();

                var subclassNode = new joinedsubclass();
                subclassNode.table = mappedTable.Name.BackTick();
                subclassNode.schema = mappedTable.Schema.BackTick();
                subclassNode.name = childEntity.Name;

                key keyNode = GetKeyNode(mappedTable);
                subclassNode.key = keyNode;

                foreach (var property in childEntity.ConcreteProperties)
                {
                    IColumn column = property.MappedColumn();
                    if (column == null) continue;

                    property propNode = ProcessProperty(property, column);
                    subclassNode.AddProperty(propNode);
                }
                classNode.AddItem1(subclassNode);

                var referenceMapper = new ReferenceMapper();
                referenceMapper.ProcessReferences(childEntity, item => subclassNode.AddItem(item));

                ProcessInheritance(childEntity, subclassNode);
            }
        }
예제 #22
0
        private void ProcessEntityTablePerClassHierarchy(Entity entity, @class classNode)
        {
            foreach (var childEntity in entity.Children)
            {
                var subclassNode = new subclass();

                subclassNode.name = childEntity.Name;
                subclassNode.discriminatorvalue = childEntity.DiscriminatorValue;

                foreach (var property in childEntity.ConcreteProperties)
                {
                    IColumn column = property.MappedColumn();
                    if (column == null) continue;

                    property propNode = ProcessProperty(property, column);
                    subclassNode.AddProperty(propNode);
                }
                var referenceMapper = new ReferenceMapper();
                referenceMapper.ProcessReferences(childEntity, item => subclassNode.AddItem(item));

                classNode.AddItem1(subclassNode);
            }
            classNode.discriminator = new discriminator();
            classNode.discriminator.force = entity.Discriminator.Force;
            //classNode.discriminator.length = entity.Discriminator.l.Force.ToString();
            //classNode.discriminator.notnull = entity.Discriminator..Force.ToString();

            if (!entity.Discriminator.Insert)
            {
                classNode.discriminator.insert = entity.Discriminator.Insert;
            }
            if (entity.Discriminator.DiscriminatorType == Providers.EntityModel.Model.Enums.DiscriminatorTypes.Column)
                classNode.discriminator.column = entity.Discriminator.ColumnName;
            else
                classNode.discriminator.formula = entity.Discriminator.Formula;
        }
예제 #23
0
 private void ProcessEntityKey(Entity entity, @class newClass, ITable table)
 {
     // We do nothing with EntityKeyType.Empty, as there is nothing to do.
     if (entity.Key.KeyType == EntityKeyType.Properties)
         ProcessPropertyEntityKey(entity, newClass, table);
     else if (entity.Key.KeyType == EntityKeyType.Component)
     {
         compositeid cId = GetCompositeIDWithComponent(entity.Key.Component);
         newClass.SetCompositeId(cId);
     }
 }
예제 #24
0
        private Mapping CreateMappingFor(Entity entity, @class hEntity, IDatabase database, string defaultSchema)
        {
            if (hEntity.table == null)
                return null;

            Mapping mapping = new MappingImpl();
            string schema = string.IsNullOrEmpty(hEntity.schema) ? defaultSchema : hEntity.schema;
            var table = database.GetTable(hEntity.table.UnBackTick(), schema.UnBackTick());

            if (table == null)
            {
                // create the table
                table = entityProcessor.CreateTable(entity);
                database.AddTable(table);
            }

            mapping.FromTable = table;
            mapping.ToEntity = entity;

            return mapping;
        }
예제 #25
0
 private void ProcessVersionProperty(hibernatemapping hm, @class hClass, Entity newEntity, Mapping mapping, ParseResults parseResults)
 {
     version version = hClass.Version();
     var typeName = string.IsNullOrEmpty(version.type) ? "int" : version.type;
     var columnName = string.IsNullOrEmpty(version.column1) ? version.name : version.column1;
     var property = CreateProperty(newEntity, mapping, typeName, version.name, columnName, "");
     property.SetPropertyIsVersion(true);
     SetPropertyInfoFromParsedCode(property, parseResults, hm.@namespace, mapping.FromTable.Schema, hClass.name);
 }
예제 #26
0
 public static void AddItem <T>(this @class theClass, T property) where T : class
 {
     AddItem(theClass, property);
 }
예제 #27
0
 public static void SetCompositeId(this @class theClass, compositeid compositeId)
 {
     theClass.Item = compositeId;
 }
예제 #28
0
 /// <summary>
 /// Gets the Id of the @class if it exists
 /// </summary>
 /// <param name="theClass"></param>
 /// <returns></returns>
 public static id Id(this @class theClass)
 {
     return(theClass.Item as id);
 }
예제 #29
0
        private void ProcessCollection(
			@class hClass,
			key keyNode,
			index indexNode,
			manytomany many,
			string className,
			string schema,
			string tableName,
			string propertyName,
			string cascade,
			AssociationType associationType,
			string whereClause,
			collectionFetchMode fetchMode,
			bool inverse,
			collectionLazy lazy,
			string orderByClause)
        {
            #region OrderBy
            string orderByPropertyName = "";
            bool orderByIsAsc = true;

            if (!string.IsNullOrWhiteSpace(orderByClause))
            {
                orderByClause = orderByClause.Trim();

                if (orderByClause.EndsWith(" desc", StringComparison.InvariantCultureIgnoreCase))
                {
                    orderByIsAsc = false;
                    orderByPropertyName = orderByClause.Substring(0, orderByClause.LastIndexOf(" desc", StringComparison.InvariantCultureIgnoreCase)).Trim();
                }
                else if (orderByClause.EndsWith(" asc", StringComparison.InvariantCultureIgnoreCase))
                {
                    orderByIsAsc = false;
                    orderByPropertyName = orderByClause.Substring(0, orderByClause.LastIndexOf(" asc", StringComparison.InvariantCultureIgnoreCase)).Trim();
                }
                else
                    orderByPropertyName = orderByClause;
            }
            #endregion

            string indexName = null;

            if (indexNode != null)
            {
                if (indexNode.column != null && indexNode.column.Count() > 0)
                    indexName = indexNode.column[0].name;
                else
                    indexName = indexNode.column1;
            }
            if (many != null)
            {
                var fkColumns = GetColumnNames(many.column, many.Columns()).ToList();
                string thisEntityName;
                string otherEntityName;
                EntityLoader.IsNameFullyQualified(hClass.name, out thisEntityName);
                EntityLoader.IsNameFullyQualified(many.@class, out otherEntityName);

                var collectionInfo = new AssociationInformation
                                        {
                                            PropertyName = propertyName,
                                            ForeignKeyColumnNames = fkColumns,
                                            ForeignKeyBelongsToThisTable = !ForeignKeyBelongsToThisTable(hClass, fkColumns),
                                            AssociationTableName = new AssociationInformation.TableNameType(schema, tableName),
                                            ThisEntityName = thisEntityName,
                                            OtherEntityName = otherEntityName,
                                            Cardinality = Cardinality.Many,
                                            CollectionCascade = ArchAngel.Interfaces.NHibernateEnums.Helper.GetCollectionCascadeType(cascade),
                                            CollectionLazy = ArchAngel.Interfaces.NHibernateEnums.Helper.GetCollectionLazyType(lazy.ToString()),
                                            CollectionFetchMode = (CollectionFetchModes)Enum.Parse(typeof(CollectionFetchModes), fetchMode.ToString(), true),
                                            IndexColumn = indexName,
                                            WhereClause = whereClause,
                                            AssociationType = associationType,
                                            Inverse = inverse ? ArchAngel.Interfaces.NHibernateEnums.BooleanInheritedTypes.@true : ArchAngel.Interfaces.NHibernateEnums.BooleanInheritedTypes.@false,
                                            OrderByColumnName = orderByPropertyName,
                                            OrderByIsAsc = orderByIsAsc
                                        };
                associationInformation.Add(collectionInfo);
            }
            else
            {
                var fkColumns = GetColumnNames(keyNode.column1, keyNode.Columns()).ToList();
                string thisEntityName;
                string otherEntityName;
                EntityLoader.IsNameFullyQualified(hClass.name, out thisEntityName);
                EntityLoader.IsNameFullyQualified(className, out otherEntityName);

                bool topLevelInverse = ArchAngel.Interfaces.SharedData.CurrentProject.GetProjectDefaultInverse();
                BooleanInheritedTypes inverseValue = inverse ? BooleanInheritedTypes.@true : BooleanInheritedTypes.@false;

                if ((inverseValue == BooleanInheritedTypes.@false && topLevelInverse == false) ||
                    (inverseValue == BooleanInheritedTypes.@true && topLevelInverse == true))
                    inverseValue = BooleanInheritedTypes.inherit_default;

                var collectionInfo = new AssociationInformation
                                        {
                                            PropertyName = propertyName,
                                            ForeignKeyColumnNames = fkColumns,
                                            ForeignKeyBelongsToThisTable = ForeignKeyBelongsToThisTable(hClass, fkColumns), // GFH
                                            ThisEntityName = thisEntityName,
                                            OtherEntityName = otherEntityName,
                                            Cardinality = Cardinality.Many,
                                            CollectionCascade = ArchAngel.Interfaces.NHibernateEnums.Helper.GetCollectionCascadeType(cascade),
                                            CollectionLazy = ArchAngel.Interfaces.NHibernateEnums.Helper.GetCollectionLazyType(lazy.ToString()),
                                            CollectionFetchMode = (CollectionFetchModes)Enum.Parse(typeof(CollectionFetchModes), fetchMode.ToString(), true),
                                            IndexColumn = indexName,
                                            AssociationType = associationType,
                                            Inverse = inverseValue,
                                            OrderByColumnName = orderByPropertyName,
                                            OrderByIsAsc = orderByIsAsc
                                        };
                associationInformation.Add(collectionInfo);
            }
        }
예제 #30
0
        private void ProcessPropertyEntityKey(Entity entity, @class newClass, ITable table)
        {
            var keyProperties = entity.Key.Properties;

            bool isSingleColumnPK = keyProperties.Count() == 1;

            if (isSingleColumnPK)
            {
                id newClassId = SetupSingleColumnPrimaryKey(entity);
                newClass.SetId(newClassId);
            }
            else
            {
                compositeid cId = GetCompositeIDWithProperties(table, entity);
                newClass.SetCompositeId(cId);
            }
        }
예제 #31
0
 private void ProcessCompositeKey(hibernatemapping hm, @class hClass, Entity newEntity, Mapping mapping, ParseResults parseResults, compositeid hCompId)
 {
     foreach (var prop in hCompId.KeyProperties())
     {
         var idProperty = CreateProperty(newEntity, mapping, prop);
         SetPropertyInfoFromParsedCode(idProperty, parseResults, hm.@namespace, mapping.FromTable.Schema, hClass.name);
         idProperty.IsKeyProperty = true;
     }
 }
예제 #32
0
        public @class ProcessEntity(Entity entity)
        {
            Log.DebugFormat("Processing entity {0}", entity.Name);
            var newClass = new @class { name = entity.Name };
            IList<ITable> mappedTables = entity.MappedTables().ToList();
            // One Entity to one or more tables
            ITable table = GetPrimaryTable(entity);

            if (table != null && !string.IsNullOrEmpty(table.Name))
                newClass.table = table.Name.BackTick();

            if (table != null && !string.IsNullOrEmpty(table.Schema))
                newClass.schema = table.Schema.BackTick();

            var entityDefaultLazy = entity.GetEntityLazy();

            if (entity.GetEntityLazy() == Interfaces.NHibernateEnums.EntityLazyTypes.inherit_default)
                newClass.lazy = ArchAngel.Interfaces.SharedData.CurrentProject.GetProjectDefaultLazy();
            else
                newClass.lazy = entityDefaultLazy == Interfaces.NHibernateEnums.EntityLazyTypes.@true;

            newClass.lazySpecified = !newClass.lazy;

            newClass.batchsize = entity.GetEntityBatchSize();
            newClass.batchsizeSpecified = entity.GetEntityBatchSize() != 1;

            if (entity.GetEntityDynamicInsert())
                newClass.dynamicinsert = true;

            if (entity.GetEntityDynamicUpdate())
                newClass.dynamicupdate = true;

            newClass.@abstract = entity.IsAbstract;

            if (entity.IsAbstract)
                newClass.abstractSpecified = true;

            newClass.mutable = entity.GetEntityMutable();
            newClass.optimisticlock = (optimisticLockMode)Enum.Parse(typeof(optimisticLockMode), entity.GetEntityOptimisticLock().ToString(), true);
            newClass.selectbeforeupdate = entity.GetEntitySelectBeforeUpdate();

            if (entity.Cache.Usage != Cache.UsageTypes.None)
            {
                newClass.cache = new cache()
                {
                    include = (cacheInclude)Enum.Parse(typeof(cacheInclude), entity.Cache.Include.ToString().Replace("_", ""), true),
                    region = entity.Cache.Region
                };
                switch (entity.Cache.Usage)
                {
                    case Cache.UsageTypes.NonStrict_Read_Write:
                        newClass.cache.usage = cacheUsage.nonstrictreadwrite;
                        break;
                    case Cache.UsageTypes.Read_Only:
                        newClass.cache.usage = cacheUsage.@readonly;
                        break;
                    case Cache.UsageTypes.Read_Write:
                        newClass.cache.usage = cacheUsage.readwrite;
                        break;
                    case Cache.UsageTypes.Transactional:
                        newClass.cache.usage = cacheUsage.transactional;
                        break;
                    default:
                        throw new NotImplementedException("This cache type not implemented yet: " + entity.Cache.Usage.ToString());
                }
            }

            if (entity.GetEntityBatchSize() != 1)
                newClass.batchsize = entity.GetEntityBatchSize();

            if (!string.IsNullOrWhiteSpace(entity.GetEntityProxy()))
                newClass.proxy = entity.GetEntityProxy();

            if (!string.IsNullOrWhiteSpace(entity.GetEntityPersister()))
                newClass.persister = entity.GetEntityPersister();

            string sqlWhere = entity.GetEntitySqlWhereClause();

            if (!string.IsNullOrEmpty(sqlWhere))
                newClass.where = sqlWhere;

            // bool isSingleColumnPK = false;

            if (entity.IsAbstract)
            {
                // This is an abstract class in Table Per Concrete Class inheritance. The child entities
                // should have properties of the same name.
                Entity firstChild = entity.Children.FirstOrDefault();

                while (firstChild != null && firstChild.IsAbstract)
                    firstChild = firstChild.Children.FirstOrDefault();

                if (firstChild != null)
                {
                    ITable childTable = GetPrimaryTable(firstChild);
                    ProcessEntityKey(firstChild, newClass, childTable);
                    // isSingleColumnPK = childTable.ColumnsInPrimaryKey.Count() == 1;

                    foreach (var property in entity.Properties.OrderBy(p => p.Name))
                    {
                        if (firstChild.PropertiesHiddenByAbstractParent.Single(p => p.Name == property.Name).IsKeyProperty)
                            continue;

                        var mappedColumn = firstChild.PropertiesHiddenByAbstractParent.Single(p => p.Name == property.Name).MappedColumn();
                        property prop = new property { name = property.Name, column = mappedColumn.Name.BackTick() };
                        //AddExtraInfoToProperty(prop, property);
                        newClass.AddProperty(prop);
                    }
                }
                foreach (Entity child in entity.Children)
                {
                    Entity theChild = child;

                    while (theChild != null && theChild.IsAbstract)
                        theChild = theChild.Children.FirstOrDefault();

                    ITable mappedTable = theChild.MappedTables().First();

                    unionsubclass union = new unionsubclass()
                    {
                        name = theChild.Name,
                        table = mappedTable.Name.BackTick()
                    };
                    newClass.AddItem1(union);

                    List<property> unionProperties = new List<property>();

                    foreach (Property prop in theChild.ConcreteProperties)
                    {
                        if (prop.IsKeyProperty)
                            continue;

                        unionProperties.Add(
                        new property()
                        {
                            name = prop.Name,
                            column = prop.MappedColumn().Name.BackTick()
                        });
                        //AddExtraInfoToProperty(prop, property);
                    }
                    union.Items = unionProperties.ToArray();
                }
            }
            else
            {
                ProcessEntityKey(entity, newClass, table);
                // isSingleColumnPK = table.ColumnsInPrimaryKey.Count() == 1;
            }
            var propertiesAlreadyHandled = new List<Property>();

            foreach (ITable joinedTable in mappedTables.OrderBy(t => t.Name))
            {
                if (joinedTable == table)
                    continue;

                join joinNode = new join();
                joinNode.table = joinedTable.Name.BackTick();
                joinNode.schema = joinedTable.Schema.BackTick();
                int numPrimaryKeyColumns = joinedTable.ColumnsInPrimaryKey.Count();

                if (numPrimaryKeyColumns > 0)
                {
                    key keyNode = GetKeyNode(joinedTable);
                    joinNode.key = keyNode;
                }

                foreach (var property in entity.Properties.OrderBy(p => p.Name))
                {
                    var mappedColumn = property.MappedColumn();

                    if (mappedColumn == null || mappedColumn.Parent != joinedTable)
                        continue;

                    property prop = new property { name = property.Name, column = mappedColumn.Name.BackTick() };
                    AddExtraInfoToProperty(prop, property);
                    joinNode.AddProperty(prop);
                    propertiesAlreadyHandled.Add(property);
                }
                newClass.AddItem1(joinNode);
            }
            var versionProperty = entity.Properties.FirstOrDefault(p => p.GetPropertyIsVersion());

            if (versionProperty != null)
            {
                version versionNode = new version();
                versionNode.column1 = versionProperty.MappedColumn().Name.BackTick();
                versionNode.name = versionProperty.Name;
                versionNode.type = versionProperty.NHibernateType;
                // AddExtraInfoToProperty(prop, property);
                newClass.SetVersion(versionNode);
                propertiesAlreadyHandled.Add(versionProperty);
            }

            //foreach (var prop in ProcessProperties(entity.Properties.Except(propertiesAlreadyHandled).Except(entity.ForeignKeyPropertiesToExclude), isSingleColumnPK).OrderBy(p => p.name))
            foreach (var prop in ProcessProperties(entity.Properties.Except(propertiesAlreadyHandled).Except(entity.ForeignKeyPropertiesToExclude)).OrderBy(p => p.name))
                newClass.AddProperty(prop);

            // Process components, skip component used as Key.
            foreach (var component in ProcessComponent(entity.Components.Except(new[] { entity.Key.Component })).OrderBy(c => c.name))
                newClass.AddComponent(component);

            ProcessInheritance(entity, newClass);

            var referenceMapper = new ReferenceMapper();
            referenceMapper.ProcessReferences(entity, item => newClass.AddItem(item));
            return newClass;
        }
예제 #33
0
 /// <summary>
 /// Sets the Version of the @class
 /// </summary>
 /// <param name="theClass"></param>
 /// <param name="version"></param>
 /// <returns></returns>
 public static void SetVersion(this @class theClass, version version)
 {
     theClass.Item1 = version;
 }
예제 #34
0
        private bool ForeignKeyBelongsToThisTable(@class hClass, List<string> fkColumns)
        {
            foreach (var fkCol in fkColumns)
                if (hClass.Properties().Count(p => p.name == fkCol.UnBackTick()) == 0)
                    if (hClass.CompositeId() != null && hClass.CompositeId().KeyProperties().Count(p => p.name.ToLowerInvariant() == fkCol.UnBackTick().ToLowerInvariant()) == 0)
                        return false;

            return true;
        }
예제 #35
0
 public static void SetId(this @class theClass, id Id)
 {
     theClass.Item = Id;
 }