Added helpers.
This commit is contained in:
Родитель
f817af799c
Коммит
61d09e2324
|
@ -287,6 +287,99 @@ void LoadMetadata(DataConnection dataConnection)
|
|||
}
|
||||
}
|
||||
|
||||
Table GetTable(string name)
|
||||
{
|
||||
Table tbl;
|
||||
|
||||
if (Tables.TryGetValue(name, out tbl))
|
||||
return tbl;
|
||||
|
||||
WriteLine("#error Table '" + name + "' not found.");
|
||||
WriteLine("/*");
|
||||
WriteLine("\tExisting tables:");
|
||||
WriteLine("");
|
||||
|
||||
foreach (var key in Tables.Keys)
|
||||
WriteLine("\t" + key);
|
||||
|
||||
WriteLine(" */");
|
||||
|
||||
throw new ArgumentException("Table '" + name + "' not found.");
|
||||
}
|
||||
|
||||
Procedure GetProcedure(string name)
|
||||
{
|
||||
Procedure proc;
|
||||
|
||||
if (Procedures.TryGetValue(name, out proc))
|
||||
return proc;
|
||||
|
||||
WriteLine("#error Procedure '" + name + "' not found.");
|
||||
WriteLine("");
|
||||
WriteLine("/*");
|
||||
WriteLine("\tExisting procedures:");
|
||||
WriteLine("");
|
||||
|
||||
foreach (var key in Procedures.Keys)
|
||||
WriteLine("\t" + key);
|
||||
|
||||
WriteLine(" */");
|
||||
|
||||
throw new ArgumentException("Procedure '" + name + "' not found.");
|
||||
}
|
||||
|
||||
Column GetColumn(string tableName, string columnName)
|
||||
{
|
||||
var tbl = GetTable(tableName);
|
||||
|
||||
Column col;
|
||||
|
||||
if (tbl.Columns.TryGetValue(columnName, out col))
|
||||
return col;
|
||||
|
||||
WriteLine("#error Column '" + tableName + "'.'" + columnName + "' not found.");
|
||||
WriteLine("");
|
||||
WriteLine("/*");
|
||||
WriteLine("\tExisting '" + tableName + "'columns:");
|
||||
WriteLine("");
|
||||
|
||||
foreach (var key in tbl.Columns.Keys)
|
||||
WriteLine("\t" + key);
|
||||
|
||||
WriteLine(" */");
|
||||
|
||||
throw new ArgumentException("Column '" + tableName + "'.'" + columnName + "' not found.");
|
||||
}
|
||||
|
||||
ForeignKey GetFK(string tableName, string fkName)
|
||||
{
|
||||
return GetForeignKey(tableName, fkName);
|
||||
}
|
||||
|
||||
ForeignKey GetForeignKey(string tableName, string fkName)
|
||||
{
|
||||
var tbl = GetTable(tableName);
|
||||
|
||||
ForeignKey col;
|
||||
|
||||
if (tbl.ForeignKeys.TryGetValue(fkName, out col))
|
||||
return col;
|
||||
|
||||
WriteLine("#error FK '" + tableName + "'.'" + fkName + "' not found.");
|
||||
WriteLine("");
|
||||
WriteLine("/*");
|
||||
WriteLine("\tExisting '" + tableName + "'FKs:");
|
||||
WriteLine("");
|
||||
|
||||
foreach (var key in tbl.ForeignKeys.Keys)
|
||||
WriteLine("\t" + key);
|
||||
|
||||
WriteLine(" */");
|
||||
|
||||
throw new ArgumentException("FK '" + tableName + "'.'" + fkName + "' not found.");
|
||||
}
|
||||
|
||||
|
||||
Dictionary<string,Table> Tables = new Dictionary<string,Table> ();
|
||||
Dictionary<string,Procedure> Procedures = new Dictionary<string,Procedure>();
|
||||
|
||||
|
|
|
@ -6,8 +6,11 @@
|
|||
//---------------------------------------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
||||
using LinqToDB;
|
||||
using LinqToDB.Common;
|
||||
using LinqToDB.Data;
|
||||
using LinqToDB.Mapping;
|
||||
|
||||
namespace DB2DataContext
|
||||
|
@ -199,4 +202,17 @@ namespace DB2DataContext
|
|||
{
|
||||
[PrimaryKey, Identity] public int ID { get; set; } // INTEGER
|
||||
}
|
||||
|
||||
public static partial class TESTDATADBStoredProcedures
|
||||
{
|
||||
#region PERSON_SELECTBYKEY
|
||||
|
||||
public static IEnumerable<Person> PERSON_SELECTBYKEY(this DataConnection dataConnection, int? ID)
|
||||
{
|
||||
return dataConnection.QueryProc<Person>("ADMINISTRATOR.PERSON_SELECTBYKEY",
|
||||
new DataParameter("ID", ID));
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,5 +13,11 @@
|
|||
//GetSchemaOptions.ExcludedSchemas = new[] { "TestUser", "SYSSTAT" };
|
||||
|
||||
LoadDB2Metadata("DBHost", "50000", "TESTDATA", "Administrator", "TestPassword");
|
||||
|
||||
GetProcedure("ADMINISTRATOR.PERSON_SELECTBYKEY").ResultTable = GetTable("ADMINISTRATOR.Person");
|
||||
|
||||
//GetColumn("ADMINISTRATOR.Person", "ID").MemberName = "122";
|
||||
//GetFK ("ADMINISTRATOR.Person", "ID1").MemberName = "122";
|
||||
|
||||
GenerateModel();
|
||||
#>
|
||||
|
|
Загрузка…
Ссылка в новой задаче