diff --git a/Templates/DataModel.ttinclude b/Templates/DataModel.ttinclude index 9b40add..685fadc 100644 --- a/Templates/DataModel.ttinclude +++ b/Templates/DataModel.ttinclude @@ -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 Tables = new Dictionary (); Dictionary Procedures = new Dictionary(); diff --git a/Tests/LinqToDB/DB2.generated.cs b/Tests/LinqToDB/DB2.generated.cs index 6c069a0..1e20d9d 100644 --- a/Tests/LinqToDB/DB2.generated.cs +++ b/Tests/LinqToDB/DB2.generated.cs @@ -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_SELECTBYKEY(this DataConnection dataConnection, int? ID) + { + return dataConnection.QueryProc("ADMINISTRATOR.PERSON_SELECTBYKEY", + new DataParameter("ID", ID)); + } + + #endregion + } } diff --git a/Tests/LinqToDB/DB2.tt b/Tests/LinqToDB/DB2.tt index f0e3c0f..c0811f5 100644 --- a/Tests/LinqToDB/DB2.tt +++ b/Tests/LinqToDB/DB2.tt @@ -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(); #>