private void SaveRelations(XmlWriter writer)
        {
            var orderedRelationType = new List <IRelationType>(this.ObjectFactory.MetaPopulation.RelationTypes);

            orderedRelationType.Sort();
            foreach (var relation in orderedRelationType)
            {
                if (relation.AssociationType.ObjectType.ExistClass)
                {
                    var role = relation.RoleType;

                    var cmdText = @"
SELECT " + Mapping.ColumnNameForAssociation + "," + Mapping.ColumnNameForRole + @"
FROM " + this.SchemaName + "." + this.Mapping.GetTableName(relation) + @"
ORDER BY " + Mapping.ColumnNameForAssociation + "," + Mapping.ColumnNameForRole;

                    using (var command = this.CreateCommand(cmdText))
                    {
                        using (DbDataReader reader = command.ExecuteReader())
                        {
                            if (role.IsMany)
                            {
                                using (var relationTypeManyXmlWriter = new RelationTypeManyXmlWriter(relation, writer))
                                {
                                    while (reader.Read())
                                    {
                                        var a = long.Parse(reader.GetValue(0).ToString());
                                        var r = long.Parse(reader.GetValue(1).ToString());
                                        relationTypeManyXmlWriter.Write(a, r);
                                    }

                                    relationTypeManyXmlWriter.Close();
                                }
                            }
                            else
                            {
                                using (var relationTypeOneXmlWriter = new RelationTypeOneXmlWriter(relation, writer))
                                {
                                    while (reader.Read())
                                    {
                                        var a = long.Parse(reader.GetValue(0).ToString());

                                        if (role.ObjectType is IUnit)
                                        {
                                            var unitTypeTag = ((IUnit)role.ObjectType).UnitTag;
                                            var r           = reader.GetValue(1);
                                            var content     = Serialization.WriteString(unitTypeTag, r);
                                            relationTypeOneXmlWriter.Write(a, content);
                                        }
                                        else
                                        {
                                            var r = reader.GetValue(1);
                                            relationTypeOneXmlWriter.Write(a, XmlConvert.ToString(long.Parse(r.ToString())));
                                        }
                                    }

                                    relationTypeOneXmlWriter.Close();
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #2
0
        private void SaveRelations(XmlWriter writer)
        {
            var orderedRelationType = new List<IRelationType>(this.ObjectFactory.MetaPopulation.RelationTypes);
            orderedRelationType.Sort();
            foreach (var relation in orderedRelationType)
            {
                if (relation.AssociationType.ObjectType.ExistClass)
                {
                    var role = relation.RoleType;

                    var cmdText = @"
            SELECT " + Mapping.ColumnNameForAssociation + "," + Mapping.ColumnNameForRole + @"
            FROM " + this.SchemaName + "." + this.Mapping.GetTableName(relation) + @"
            ORDER BY " + Mapping.ColumnNameForAssociation + "," + Mapping.ColumnNameForRole;

                    using (var command = this.CreateCommand(cmdText))
                    {
                        using (DbDataReader reader = command.ExecuteReader())
                        {
                            if (role.IsMany)
                            {
                                using (var relationTypeManyXmlWriter = new RelationTypeManyXmlWriter(relation, writer))
                                {
                                    while (reader.Read())
                                    {
                                        var a = long.Parse(reader.GetValue(0).ToString());
                                        var r = long.Parse(reader.GetValue(1).ToString());
                                        relationTypeManyXmlWriter.Write(a, r);
                                    }

                                    relationTypeManyXmlWriter.Close();
                                }
                            }
                            else
                            {
                                using (var relationTypeOneXmlWriter = new RelationTypeOneXmlWriter(relation, writer))
                                {
                                    while (reader.Read())
                                    {
                                        var a = long.Parse(reader.GetValue(0).ToString());

                                        if (role.ObjectType is IUnit)
                                        {
                                            var unitTypeTag = ((IUnit)role.ObjectType).UnitTag;
                                            var r = reader.GetValue(1);
                                            var content = Serialization.WriteString(unitTypeTag, r);
                                            relationTypeOneXmlWriter.Write(a, content);
                                        }
                                        else
                                        {
                                            var r = reader.GetValue(1);
                                            relationTypeOneXmlWriter.Write(a, XmlConvert.ToString(long.Parse(r.ToString())));
                                        }
                                    }

                                    relationTypeOneXmlWriter.Close();
                                }
                            }
                        }
                    }
                }
            }
        }