diff options
Diffstat (limited to 'ComicRackWebViewer/LinqToDB.Templates/LinqToDB.SqlServer.ttinclude')
-rw-r--r-- | ComicRackWebViewer/LinqToDB.Templates/LinqToDB.SqlServer.ttinclude | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/ComicRackWebViewer/LinqToDB.Templates/LinqToDB.SqlServer.ttinclude b/ComicRackWebViewer/LinqToDB.Templates/LinqToDB.SqlServer.ttinclude new file mode 100644 index 0000000..04354c5 --- /dev/null +++ b/ComicRackWebViewer/LinqToDB.Templates/LinqToDB.SqlServer.ttinclude @@ -0,0 +1,107 @@ +<#@ include file="LinqToDB.ttinclude" #> +<# + LinqToDB.DataProvider.SqlServer.SqlServerTools.ResolveSqlTypes( + typeof(Microsoft.SqlServer.Types.SqlGeography).Assembly); + + { + var afterGenerateLinqToDBModel = AfterGenerateLinqToDBModel; + AfterGenerateLinqToDBModel = () => + { + afterGenerateLinqToDBModel(); + GenerateSqlServerTypes(); + }; + } +#> +<#+ +void GenerateSqlServerTypes() +{ + Model.Usings.Add("System.Collections.Generic"); + Model.Usings.Add("System.Linq.Expressions"); + Model.Usings.Add("System.Reflection"); + Model.Usings.Add("LinqToDB"); + Model.Usings.Add("LinqToDB.DataProvider.SqlServer"); + + DataContextObject.Members.Add( + new MemberGroup + { + Region = "FreeTextTable", + Members = + { + new Class("FreeTextKey<T>", + new MemberGroup + { + IsCompact = true, + Members = + { + new Field("T", "Key"), + new Field("int", "Rank") + } + }) + { + IsPartial = false + }, + + new Method("ITable<FreeTextKey<TKey>>", "FreeTextTable<TTable,TKey>", + new[] { "string field", "string text" }, + new[] + { + "return this.GetTable<FreeTextKey<TKey>>(", + " this,", + " ((MethodInfo)(MethodBase.GetCurrentMethod())).MakeGenericMethod(typeof(TTable), typeof(TKey)),", + " field,", + " text);", + }) + { + Attributes = { new Attribute("FreeTextTableExpression") } + }, + new Method("ITable<FreeTextKey<TKey>>", "FreeTextTable<TTable,TKey>", + new[] { "Expression<Func<TTable,string>> fieldSelector", "string text" }, + new[] + { + "return this.GetTable<FreeTextKey<TKey>>(", + " this,", + " ((MethodInfo)(MethodBase.GetCurrentMethod())).MakeGenericMethod(typeof(TTable), typeof(TKey)),", + " fieldSelector,", + " text);", + }) + { + Attributes = { new Attribute("FreeTextTableExpression") } + }, + } + } + ); +} + +LinqToDB.Data.DataConnection GetSqlServerConnection(string connectionString) +{ + return LinqToDB.DataProvider.SqlServer.SqlServerTools.CreateDataConnection(connectionString); +} + +LinqToDB.Data.DataConnection GetSqlServerConnection(string server, string database) +{ + return GetSqlServerConnection(string.Format("Data Source={0};Database={1};Integrated Security=SSPI", server, database)); +} + +LinqToDB.Data.DataConnection GetSqlServerConnection(string server, string database, string user, string password) +{ + return GetSqlServerConnection(string.Format("Server={0};Database={1};User Id={2};Password={3};", server, database, user, password)); +} + +void LoadSqlServerMetadata(string connectionString) +{ + var dataConnection = GetSqlServerConnection(connectionString); + LoadMetadata(dataConnection); +} + +void LoadSqlServerMetadata(string server, string database) +{ + var dataConnection = GetSqlServerConnection(server, database); + LoadMetadata(dataConnection); +} + +void LoadSqlServerMetadata(string server, string database, string user, string password) +{ + var dataConnection = GetSqlServerConnection(server, database, user, password); + LoadMetadata(dataConnection); +} +#> |