public CatalogDefinition ToCatalog(DataSet dataset)
        {
            var schema  = ToSchema(dataset.Tables);
            var catalog = new CatalogDefinition();

            catalog.AddSchema(schema);
            return(catalog);
        }
예제 #2
0
        public void Entity_ToCompressedStream()
        {
            var catalog = new CatalogDefinition("company_catalog", _owner);
            var schema  = catalog.AddSchema(_owner);

            var jobTable    = schema.AddTable("job");
            var jobPkColumn = jobTable.AddColumn("id", DbType.Int32);

            jobPkColumn.IsPrimaryKey = true;
            jobPkColumn.PrimaryKey.IsAutoIncrement = true;

            var jobNameColumn = jobTable.AddColumn("name", DbType.String);

            jobNameColumn.MaxLength = 256;
            jobNameColumn.IsUnique  = true;

            var employeeTable = schema.AddTable("employee");

            employeeTable.AddComment("employees and their date of employment");

            var pkColumn = employeeTable.AddColumn("id", DbType.Int32);

            pkColumn.IsPrimaryKey = true;
            pkColumn.PrimaryKey.IsAutoIncrement = true;

            var jobIdColumn = employeeTable.AddColumn("job_id", DbType.Int32);

            jobIdColumn.HasForeignKey     = true;
            jobIdColumn.ForeignKey.Schema = schema.Name;
            jobIdColumn.ForeignKey.Table  = jobTable.Name;
            jobIdColumn.ForeignKey.Column = jobPkColumn.Name;

            var firstNameColumn = employeeTable.AddColumn("first_name", DbType.String);

            firstNameColumn.MaxLength  = 256;
            firstNameColumn.IsNullable = false;

            var lastNameColumn = employeeTable.AddColumn("last_name", DbType.String);

            lastNameColumn.MaxLength  = 256;
            lastNameColumn.IsNullable = false;

            var ssnColumn = employeeTable.AddColumn("ssn", DbType.String);

            ssnColumn.MaxLength  = 11;
            ssnColumn.IsNullable = false;

            var doeColumn = employeeTable.AddColumn("doe", DbType.Date);

            doeColumn.AddComment("date of employment");
            doeColumn.IsNullable = false;

            var dobColumn = employeeTable.AddColumn("dob", DbType.Date);

            var index = employeeTable.AddIndex("employee_name_idx");

            index.AddColumn(lastNameColumn, Directions.Ascending);
            index.AddColumn(firstNameColumn);
            index.AddColumn(ssnColumn);
            index.IsUnique = true;

            using (var stream1 = catalog.ToCompressedStream())
            {
                stream1.Position = 0;
                var cat = stream1.ToEntityFromCompressedStream <CatalogDefinition>();
                using (var stream2 = cat.ToCompressedStream())
                {
                    stream1.Position = 0;
                    stream2.Position = 0;

                    Assert.AreEqual(stream1.Length, stream2.Length);

                    var bytes1 = stream1.ToArray();
                    var bytes2 = stream2.ToArray();
                    Assert.IsTrue(bytes1.SequenceEqual(bytes2));
                }
            }
        }
예제 #3
0
        public void Entity_ToJson()
        {
            var catalog = new CatalogDefinition("company_catalog", _owner);
            var schema  = catalog.AddSchema(_owner);

            var jobTable    = schema.AddTable("job");
            var jobPkColumn = jobTable.AddColumn("id", DbType.Int32);

            jobPkColumn.IsPrimaryKey = true;
            jobPkColumn.PrimaryKey.IsAutoIncrement = true;

            var jobNameColumn = jobTable.AddColumn("name", DbType.String);

            jobNameColumn.MaxLength = 256;
            jobNameColumn.IsUnique  = true;

            var employeeTable = schema.AddTable("employee");

            employeeTable.AddComment("employees and their date of employment");

            var pkColumn = employeeTable.AddColumn("id", DbType.Int32);

            pkColumn.IsPrimaryKey = true;
            pkColumn.PrimaryKey.IsAutoIncrement = true;

            var jobIdColumn = employeeTable.AddColumn("job_id", DbType.Int32);

            jobIdColumn.HasForeignKey     = true;
            jobIdColumn.ForeignKey.Schema = schema.Name;
            jobIdColumn.ForeignKey.Table  = jobTable.Name;
            jobIdColumn.ForeignKey.Column = jobPkColumn.Name;

            var firstNameColumn = employeeTable.AddColumn("first_name", DbType.String);

            firstNameColumn.MaxLength  = 256;
            firstNameColumn.IsNullable = false;

            var lastNameColumn = employeeTable.AddColumn("last_name", DbType.String);

            lastNameColumn.MaxLength  = 256;
            lastNameColumn.IsNullable = false;

            var ssnColumn = employeeTable.AddColumn("ssn", DbType.String);

            ssnColumn.MaxLength  = 11;
            ssnColumn.IsNullable = false;

            var doeColumn = employeeTable.AddColumn("doe", DbType.Date);

            doeColumn.AddComment("date of employment");
            doeColumn.IsNullable = false;

            var dobColumn = employeeTable.AddColumn("dob", DbType.Date);

            var index = employeeTable.AddIndex("employee_name_idx");

            index.AddColumn(lastNameColumn, Directions.Ascending);
            index.AddColumn(firstNameColumn);
            index.AddColumn(ssnColumn);
            index.IsUnique = true;

            var json1 = catalog.ToJson();
            var cat   = json1.ToEntity <CatalogDefinition>();
            var json2 = cat.ToJson();

            Assert.AreEqual(json1, json2);
        }