本文整理汇总了C#中TableSchema类的典型用法代码示例。如果您正苦于以下问题:C# TableSchema类的具体用法?C# TableSchema怎么用?C# TableSchema使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TableSchema类属于命名空间,在下文中一共展示了TableSchema类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteToFile
private static void WriteToFile(string folderPath, string nameSpace, bool keepDefaultValue, bool withUnderlinePrefix, MemberAccessPrivilege accessPrivilege, TableSchema tableSchema)
{
var fieldSchemaList = Mapper.Map<List<TableColumnSchema>, List<Field>>(tableSchema);
var propertySchemaList = Mapper.Map<List<TableColumnSchema>, List<Property>>(tableSchema);
var model = Mapper.Map<TableSchema, Model>(tableSchema);
// update flag to decide keeping default value or not
fieldSchemaList.Each(field => field.KeepDefaultValue = keepDefaultValue);
// update flag for nameing rule -- underline prefix
fieldSchemaList.Each(field => field.WithUnderlinePrefixNamingRule = withUnderlinePrefix);
model.Namespace = nameSpace;
model.AccessPrivilege = accessPrivilege;
model.AddRange(fieldSchemaList);
model.AddRange(propertySchemaList);
var code = model.Serialize();
using (FileStream stream = new FileStream(Path.Combine(folderPath, model.ModelName + ".cs"), FileMode.OpenOrCreate))
using (var writer = new StreamWriter(stream, System.Text.Encoding.UTF8))
{
stream.SetLength(0);
writer.Write(code);
writer.Flush();
writer.Close();
}
}
示例2: EndTableLoad
public override void EndTableLoad(IDbConnection connection, TableSchema table)
{
foreach (var column in table.Columns)
{
// Update sequence to make sure that next generated value
// will not cause a constraint violation.
//
if (!column.AutoIncrement)
continue;
using (var cmd = connection.CreateCommand())
{
cmd.CommandText = @"SELECT MAX(" + MakeDdlElementName(column.Name) +
@") FROM " + MakeDdlElementName(table.Name);
cmd.CommandTimeout = 0;
var maxValue = Convert.ToInt32(cmd.ExecuteScalar());
if (maxValue <= 0)
continue;
var genName = ParseName(_generatorPrefix, table.Name, column.Name);
var dbsmGenerator = new DBGenerator {Name = genName, StartValue = maxValue};
cmd.CommandText = MakeDdlGeneratorSet(dbsmGenerator);
cmd.ExecuteNonQuery();
}
}
base.EndTableLoad(connection, table);
}
示例3: GetTables
public override TableSchemaCollection GetTables ()
{
TableSchemaCollection tables = new TableSchemaCollection ();
IPooledDbConnection conn = connectionPool.Request ();
// Tables need to be ordered bacause TableSchemaCollection is "created" as sorted by default.
IDbCommand command = conn.CreateCommand (
"SELECT name, sql FROM sqlite_master WHERE type = 'table' ORDER BY name"
);
try {
using (command) {
using (IDataReader r = command.ExecuteReader()) {
while (r.Read ()) {
TableSchema table = new TableSchema (this);
table.SchemaName = "main";
table.Name = r.GetString (0);
table.IsSystemTable = table.Name.StartsWith ("sqlite_");
table.Definition = r.GetString (1);
tables.Add (table);
}
r.Close ();
}
}
} catch (Exception e) {
QueryService.RaiseException (e);
}
conn.Release ();
return tables;
}
示例4: IsManyToManyTable
public static bool IsManyToManyTable(TableSchema table)
{
return (table.Columns.Count == 2 &&
table.HasPrimaryKey() &&
table.PrimaryKeyColumns().Count == 2 &&
table.InReferences.Count == 2);
}
示例5: RunTableTemplate
public static void RunTableTemplate(CodeTemplate Parent, TableSchema SourceTable, string Path, string Template, string Output, bool debug)
{
// admin datamodel
try
{
PreserveRegionsMergeStrategy strategy = new PreserveRegionsMergeStrategy("^[ \t]*(?i:Custom)", "C#");
CodeTemplate template = null;
if (!debug)
{
template = Parent.GetCodeTemplateInstance(Parent.CodeTemplateInfo.DirectoryName + Path + "\\" + Template);
}
else
{
template = CompileTemplate(Parent, Parent.CodeTemplateInfo.DirectoryName + Path + "\\" + Template);
}
if (template != null)
{
template.SetProperty("SourceTable", SourceTable);
template.RenderToFile(Parent.CodeTemplateInfo.DirectoryName + Path + "\\" + Output, strategy);
Parent.Response.WriteLine("File: " + Output + " Created Successfully");
}
else
{
Parent.Response.WriteLine("Template is null: " + Parent.CodeTemplateInfo.DirectoryName + Path + "\\" + Template);
}
}
catch (Exception ex)
{
Parent.Response.WriteLine("Template: " + Parent.CodeTemplateInfo.DirectoryName + Path + "\\" + Template);
Parent.Response.WriteLine("Error: " + ex.Message);
Parent.Response.WriteLine("StackTrace: " + ex.StackTrace);
}
}
示例6: GetSchema
public DbSchema GetSchema()
{
var schema = new DbSchema();
var map = _configuration.BuildMapping();
var mappings = _configuration.ClassMappings;
foreach(var class_map in mappings)
{
var table = class_map.Table;
var table_schema = new TableSchema() {TableName = table.Name, SchemaName = table.Schema};
foreach (var column in table.ColumnIterator)
{
var type_code = column.GetSqlTypeCode(map);
var columnSchema = new ColumnSchema()
{
TableName = table_schema.TableName,
ColumnName = column.Name,
IsNullable = column.IsNullable,
DatabaseType = type_code.DbType,
Size = column.Length,
Scale = column.Scale,
Precision = column.Precision,
IsPrimaryKey = table.PrimaryKey.Columns.Contains(column)
};
// columnSchema.DatabaseType = property.GetSqlTypeCode(map).DbType;
table_schema.AddColumn(columnSchema);
}
schema.AddTable(table_schema);
}
return schema;
}
示例7: ShowTableEditorDialog
public bool ShowTableEditorDialog (IEditSchemaProvider schemaProvider, TableSchema table, bool create)
{
TableEditorSettings settings = new TableEditorSettings ();
settings.ConstraintSettings.CheckSettings.SupportsColumnConstraints = false;
TableEditorDialog dlg = new TableEditorDialog (schemaProvider, create, settings);
dlg.Initialize (table);
return RunDialog (dlg);
示例8: ShowTableEditorDialog
public bool ShowTableEditorDialog (IEditSchemaProvider schemaProvider, TableSchema table, bool create)
{
TableEditorSettings settings = new TableEditorSettings ();
TableEditorDialog dlg = new TableEditorDialog (schemaProvider, create, settings);
dlg.Initialize (table);
return RunDialog (dlg);
示例9: Join
/// <summary>
/// Initializes a new instance of the <see cref="Join"/> class.
/// </summary>
/// <param name="from">From.</param>
/// <param name="to">To.</param>
/// <param name="joinType">Type of the join.</param>
public Join(TableSchema.TableColumn from, TableSchema.TableColumn to, JoinType joinType,params string[] joinExpressions)
{
FromColumn = from;
ToColumn = to;
Type = joinType;
if (joinExpressions != null && joinExpressions.Length > 0)
JoinExpressions.AddRange(joinExpressions);
}
示例10: EndTableLoad
public override void EndTableLoad(IDbConnection connection, TableSchema table)
{
if (TableHasIdentityColumns(table))
using (var cmd = connection.CreateCommand())
{
cmd.CommandText = @"SET IDENTITY_INSERT " + MakeDdlElementName(table.Name) + @" OFF";
cmd.ExecuteNonQuery();
}
base.EndTableLoad(connection, table);
}
示例11: GetClassNameFromTable
/// <summary>
/// Helper to generate class name from a table
/// </summary>
/// <param name="table"></param>
/// <param name="prefix"></param>
/// <param name="strip"></param>
/// <returns>string</returns>
public static string GetClassNameFromTable(TableSchema table, string prefix, string postfix, string strip)
{
if (strip != string.Empty)
{
return prefix + table.Name.Replace(strip, "").ToCSharpIdentifier().ToPascalCase() + postfix;
}
else
{
return prefix + table.Name.ToCSharpIdentifier().ToPascalCase() + postfix;
}
}
示例12: RelationParsingTest
static RelationParsingTest()
{
NumbersSchema = new TableSchema("Numbers");
PowersSchema = new TableSchema("Powers");
NumbersSchema.Columns.AddValueColumn("Number", typeof(int), 0);
NumbersSchema.Columns.AddValueColumn("IsEven", typeof(bool), false);
PowersKeyColumn = PowersSchema.Columns.AddForeignKey("Number", NumbersSchema, "Powers");
PowersSchema.Columns.AddValueColumn("Exponent", typeof(int), 0);
PowersSchema.Columns.AddValueColumn("Value", typeof(int), 0);
}
示例13: GetTables
private static List<TableSchema> GetTables(SqlConnection con)
{
var tables = new List<TableSchema>();
string[] restrict4 = {null, null, null, "TABLE"};
string[] restrict3 = {null, null, null};
var dtTables = SqlSchemaFactory.GetSchema(con, "Tables", restrict4);
for (var i = 0; i < dtTables.Rows.Count; i++)
{
var tRow = dtTables.Rows[i];
var eTable = new TableSchema {Name = tRow["TABLE_NAME"].ToString()};
// Columns
restrict3[0] = null;
restrict3[1] = null;
restrict3[2] = eTable.Name;
var dtShema = SqlSchemaFactory.GetSchema(con, "Columns", restrict3);
if (dtShema.Rows.Count > 0)
{
eTable.Columns = new TableColumnSchema[dtShema.Rows.Count];
for (var j = 0; j < dtShema.Rows.Count; j++)
{
var cRow = dtShema.Rows[j];
var eColumn = new TableColumnSchema
{
Name = cRow["COLUMN_NAME"].ToString(),
Size = Convert.ToInt32(cRow["COLUMN_SIZE"], CultureInfo.InvariantCulture),
Type = TypeSqlToDbsm(cRow["COLUMN_DATA_TYPE"].ToString()),
Nullable = Convert.ToBoolean(cRow["IS_NULLABLE"], CultureInfo.InvariantCulture),
DefaultValue = cRow["COLUMN_DEFAULT"].ToString(),
Increment = Convert.ToInt32(cRow["IDENTITY_INCREMENT"], CultureInfo.InvariantCulture),
Seed = Convert.ToInt32(cRow["IDENTITY_SEED"], CultureInfo.InvariantCulture),
AutoIncrement = Convert.ToBoolean(cRow["IS_IDENTITY"], CultureInfo.InvariantCulture),
DecimalPrecision = Convert.ToInt32(cRow["NUMERIC_PRECISION"], CultureInfo.InvariantCulture),
DecimalScale = Convert.ToInt32(cRow["NUMERIC_SCALE"], CultureInfo.InvariantCulture)
};
eColumn.DefaultValue = string.IsNullOrEmpty(eColumn.DefaultValue)
? null
: UnBracket.ParseUnBracket(eColumn.DefaultValue);
eTable.Columns[j] = eColumn;
}
}
tables.Add(eTable);
}
return tables;
}
示例14: IsChildFKColumn
public static bool IsChildFKColumn(ColumnSchema column, TableSchema table)
{
foreach (ReferenceSchema inReference in table.InReferences)
{
foreach (ReferenceJoin join in inReference.Joins)
{
//Found the child Column...
if (join.ChildColumn.ObjectID == column.ObjectID)
{
return true;
}
}
}
return false;
}
示例15: GetTables
private static List<TableSchema> GetTables(FbConnection con)
{
string[] restrict3 = {null, null, null};
string[] restrict4 = {null, null, null, null};
var aStore = new List<TableSchema>();
restrict4[0] = null;
restrict4[1] = null;
restrict4[2] = null;
restrict4[3] = "TABLE";
var dtTables = con.GetSchema("Tables", restrict4);
for (var i = 0; i < dtTables.Rows.Count; i++)
{
var tRow = dtTables.Rows[i];
var eTable = new TableSchema {Name = tRow["TABLE_NAME"].ToString()};
// Columns
restrict3[0] = null;
restrict3[1] = null;
restrict3[2] = eTable.Name;
var dtShema = con.GetSchema("Columns", restrict3);
if (dtShema.Rows.Count > 0)
eTable.Columns = new TableColumnSchema[dtShema.Rows.Count];
for (var j = 0; j < dtShema.Rows.Count; j++)
{
var cRow = dtShema.Rows[j];
var eColumn = new TableColumnSchema
{
Name = cRow["COLUMN_NAME"].ToString(),
Size = Convert.ToInt32(cRow["COLUMN_SIZE"], CultureInfo.InvariantCulture),
Type = TypeFbToDbsm(cRow["COLUMN_DATA_TYPE"].ToString()),
Nullable = Convert.ToBoolean(cRow["IS_NULLABLE"], CultureInfo.InvariantCulture)
};
eColumn.DefaultValue = HelpDbscColumnDefault(con, eColumn.Name, eTable.Name);
eColumn.DefaultValue = string.IsNullOrEmpty(eColumn.DefaultValue) ? null : eColumn.DefaultValue;
eColumn.DecimalPrecision = cRow["NUMERIC_PRECISION"] == DBNull.Value
? 0
: Convert.ToInt32(cRow["NUMERIC_PRECISION"], CultureInfo.InvariantCulture);
eColumn.DecimalScale = Convert.ToInt32(cRow["NUMERIC_SCALE"], CultureInfo.InvariantCulture);
eTable.Columns[j] = eColumn;
}
aStore.Add(eTable);
}
return aStore;
}