예제 #1
0
        private manytoone CreateManyToOneNode(DirectedReference directedReference, ITable referenceMappedTable)
        {
            fetchMode fetchMode;
            bool insert;
            bool update;

            if (directedReference.Entity1IsFromEnd)
            {
                fetchMode = (fetchMode)Enum.Parse(typeof(fetchMode), directedReference.Reference.GetReferenceEnd1FetchMode().ToString(), true);
                insert = directedReference.Reference.GetReferenceEnd1Insert();
                update = directedReference.Reference.GetReferenceEnd1Update();
            }
            else
            {
                fetchMode = (fetchMode)Enum.Parse(typeof(fetchMode), directedReference.Reference.GetReferenceEnd2FetchMode().ToString(), true);
                insert = directedReference.Reference.GetReferenceEnd2Insert();
                update = directedReference.Reference.GetReferenceEnd2Update();
            }
            manytoone manyToOneNode = new manytoone();
            manyToOneNode.@class = directedReference.ToEntity.Name;
            manyToOneNode.name = directedReference.FromName;
            //bool notNullableColumnsExist = directedRelationship.MappedColumns.Any(mc => !mc.Source.IsNullable);
            manyToOneNode.notnull = true;
            manyToOneNode.notnullSpecified = true;
            manyToOneNode.fetch = fetchMode;
            manyToOneNode.fetchSpecified = true;
            manyToOneNode.insert = insert;
            manyToOneNode.update = update;

            ITable fromPrimaryMappedTable = EntityMapper.GetPrimaryTable(directedReference.FromEntity);
            List<IColumn> fromKeyColumns = referenceMappedTable.Relationships.First(t => t.PrimaryTable == fromPrimaryMappedTable || t.ForeignTable == fromPrimaryMappedTable).ForeignKey.Columns.ToList();

            if (fromKeyColumns.Count > 1)
                foreach (var columnNode in GetColumnNodes(fromKeyColumns))
                    manyToOneNode.AddColumn(columnNode);
            else
                manyToOneNode.column = fromKeyColumns[0].Name.BackTick();

            return manyToOneNode;
        }
예제 #2
0
        private manytoone CreateManyToOneNode(DirectedReference directedReference, DirectedRelationship directedRelationship, string cascade)
        {
            fetchMode fetchMode;
            bool insert;
            bool update;

            if (directedReference.Entity1IsFromEnd)
            {
                fetchMode = (fetchMode)Enum.Parse(typeof(fetchMode), directedReference.Reference.GetReferenceEnd1FetchMode().ToString(), true);
                insert = directedReference.Reference.GetReferenceEnd1Insert();
                update = directedReference.Reference.GetReferenceEnd1Update();
            }
            else
            {
                fetchMode = (fetchMode)Enum.Parse(typeof(fetchMode), directedReference.Reference.GetReferenceEnd2FetchMode().ToString(), true);
                insert = directedReference.Reference.GetReferenceEnd2Insert();
                update = directedReference.Reference.GetReferenceEnd2Update();
            }
            manytoone manyToOneNode = new manytoone();
            manyToOneNode.@class = directedReference.ToEntity.Name;
            manyToOneNode.name = directedReference.FromName;
            bool notNullableColumnsExist = directedRelationship.MappedColumns.Any(mc => !mc.Source.IsNullable);
            manyToOneNode.notnull = notNullableColumnsExist;
            manyToOneNode.notnullSpecified = true;
            manyToOneNode.fetch = fetchMode;
            manyToOneNode.fetchSpecified = true;
            manyToOneNode.insert = insert;
            manyToOneNode.update = update;
            manyToOneNode.cascade = cascade == "none" ? null : cascade;

            if (directedRelationship.ToTable == directedRelationship.FromTable)
            {
                if (directedRelationship.ToKey.Keytype == Providers.EntityModel.Helper.DatabaseKeyType.Primary)
                    if (directedRelationship.FromKey.Columns.Count > 1)
                        foreach (var column in GetColumnNodes(directedRelationship.FromKey.Columns))
                            manyToOneNode.AddColumn(column);
                    else
                        manyToOneNode.column = directedRelationship.FromKey.Columns[0].Name.BackTick();
                else
                    if (directedRelationship.ToKey.Columns.Count > 1)
                        foreach (var column in GetColumnNodes(directedRelationship.ToKey.Columns))
                            manyToOneNode.AddColumn(column);
                    else
                        manyToOneNode.column = directedRelationship.ToKey.Columns[0].Name.BackTick();
            }
            else
            {
                if (directedRelationship.FromKey.Columns.Count > 1)
                    foreach (var column in GetColumnNodes(directedRelationship.FromKey.Columns))
                        manyToOneNode.AddColumn(column);
                else
                    manyToOneNode.column = directedRelationship.FromKey.Columns[0].Name.BackTick();
            }
            return manyToOneNode;
        }