Example #1
0
 public EditorColumnStructure(TableEditFrame frame, ColumnStructure src, ISqlDialect dialect)
 {
     m_frame = frame;
     if (src.Domain != null)
     {
         Domain = m_frame.Domains[src.Domain];
     }
     ColumnName   = src.ColumnName;
     IsNullable   = src.IsNullable;
     CharacterSet = src.CharacterSet;
     Collation    = src.Collation;
     if (src.DefaultValue != null)
     {
         DefaultValue = src.DefaultValue.GenerateSql(dialect, src.DataType, null);
     }
     m_originalGroupId = src.GroupId;
     if (dialect == null)
     {
         DataType = src.DataType;
     }
     else
     {
         DataType = dialect.GenericTypeToSpecific(src.DataType);
     }
     Source = src;
 }
Example #2
0
 public virtual void CreateDomain(IDomainStructure domain)
 {
     if (m_dialect.DialectCaps.Domains)
     {
         Put("^create ^domain %f ", domain.FullName);
         WriteRaw(m_dialect.GenericTypeToSpecific(domain.DataType).ToString());
         EndCommand();
     }
 }
Example #3
0
        public void Init(IDomainStructure domain, ISqlDialect dialect)
        {
            m_oldDomain = domain;
            if (domain == null)
            {
                m_domain          = new DomainStructure();
                m_domain.DataType = new DbTypeString();
            }
            else
            {
                m_domain = new DomainStructure(domain);
            }
            m_dialect = dialect;
            cbxDataType.Items.Clear();
            foreach (string code in Enum.GetNames(m_dialect.SpecificTypeEnum).Sorted())
            {
                cbxDataType.Items.Add(code);
            }
            m_dataType = m_dialect.GenericTypeToSpecific(m_domain.DataType);
            propertyGrid1.SelectedObject = m_dataType;

            cbxDataType.SelectedIndex = cbxDataType.Items.IndexOf(((ISpecificType)m_dataType).Code.ToString());
            chbNullable.Checked       = m_domain.IsNullable;
        }
Example #4
0
 public static ISpecificType GenericTypeToSpecific(this ISqlDialect dialect, DbTypeBase type)
 {
     return(dialect.GenericTypeToSpecific(type, null, null));
 }
Example #5
0
        public override void WriteStructureAfterData(IDatabaseStructure db)
        {
            HashSetEx <string> usedTypes = new HashSetEx <string> {
                "String", "Int", "DateTime"
            };
            Dictionary <NameWithSchema, string> tableTypes = new Dictionary <NameWithSchema, string>();

            foreach (var tbl in db.Tables)
            {
                tableTypes[tbl.FullName] = GetMemberName(usedTypes, tbl.FullName.Name, null);
            }

            ISqlDialect dialect = m_dialect;

            using (XmlWriter xw = XmlWriter.Create(GetWorkingFileName(), new XmlWriterSettings {
                Indent = true
            }))
            {
                string XMLNS = "http://schemas.microsoft.com/linqtosql/dbml/2007";
                xw.WriteStartDocument();
                xw.WriteStartElement("Database", XMLNS);
                xw.WriteAttributeString("xmlns", XMLNS);
                xw.WriteAttributeString("Name", DatabaseName);
                xw.WriteAttributeString("Class", ClassName);
                xw.WriteAttributeString("ContextNamespace", ContextNamespace);
                xw.WriteAttributeString("EntityNamespace", EntityNamespace);
                foreach (var tbl in db.Tables)
                {
                    HashSetEx <string> tblmembers = new HashSetEx <string>();
                    string             tblmember  = tbl.FullName.Name;
                    tblmembers.Add(tblmember);
                    xw.WriteStartElement("Table");
                    xw.WriteAttributeString("Name", tbl.FullName.ToString());
                    xw.WriteAttributeString("Member", tblmember);
                    xw.WriteStartElement("Type");
                    xw.WriteAttributeString("Name", tableTypes[tbl.FullName]);
                    IPrimaryKey pk = tbl.FindConstraint <IPrimaryKey>();
                    foreach (var col in tbl.Columns)
                    {
                        string colmember = GetMemberName(tblmembers, col.ColumnName, null);
                        tblmembers.Add(colmember);
                        xw.WriteStartElement("Column");
                        if (col.ColumnName != colmember)
                        {
                            xw.WriteAttributeString("Member", colmember);
                        }
                        if (pk != null && pk.Columns.Any(c => c.ColumnName == col.ColumnName))
                        {
                            xw.WriteAttributeString("IsPrimaryKey", "true");
                        }
                        xw.WriteAttributeString("Name", col.ColumnName);
                        xw.WriteAttributeString("CanBeNull", col.IsNullable ? "true" : "false");
                        xw.WriteAttributeString("Type", GetLinqType(col.DataType));
                        xw.WriteAttributeString("DbType", dialect.GenericTypeToSpecific(col.DataType).ToString());
                        if (col.DataType.IsAutoIncrement())
                        {
                            xw.WriteAttributeString("IsDbGenerated", "true");
                        }
                        xw.WriteEndElement(); // Column
                    }
                    foreach (var fk in tbl.GetConstraints <IForeignKey>())
                    {
                        if (fk.Columns.Count != 1)
                        {
                            continue;
                        }
                        xw.WriteStartElement("Association");
                        xw.WriteAttributeString("Name", fk.Name);
                        xw.WriteAttributeString("Member", GetMemberName(tblmembers, fk.PrimaryKeyTable.Name, fk.Columns[0].ColumnName));
                        xw.WriteAttributeString("Type", tableTypes[fk.PrimaryKeyTable]);
                        xw.WriteAttributeString("ThisKey", fk.Columns[0].ColumnName);
                        xw.WriteAttributeString("OtherKey", fk.PrimaryKeyColumns[0].ColumnName);
                        xw.WriteAttributeString("IsForeignKey", "true");
                        xw.WriteEndElement(); // Association
                    }
                    xw.WriteEndElement();     // Type
                    xw.WriteEndElement();     // Table
                }
                xw.WriteEndElement();         // Database
                xw.WriteEndDocument();
            }
        }
Example #6
0
 public virtual ISpecificType GenericTypeToSpecific(DbTypeBase generic, IMigrationProfile profile, IProgressInfo progress)
 {
     return(m_dialect.GenericTypeToSpecific(generic, profile, progress));
 }