public static IEnumerable <TProxy> Get <TProxy>(this SqlConnectionString cs, string sql) where TProxy : new() { var table = cs.GetDataTable(sql); return(table.ReadProxies <TProxy>()); }
//private static DataTable GetDataTable(this SqlConnectionString cs, SqlTableQuery query) //{ // var dataTable = new DataTable(query.SchemaQualifiedTableName); // var sql = query.ToSql(); // return cs.GetDataTable(sql, dataTable); //} /// <summary> /// Opens a connection to an identified data source /// </summary> /// <param name="cs">Provides access to the data source</param> /// <returns></returns> public static SqlConnection OpenConnection(this SqlConnectionString cs) { var connection = new SqlConnection(cs); connection.Open(); return(connection); }
public static IEnumerable <SchemaTableRecord> GetResultSchema(this SqlConnectionString cs, string sql) { using (var connection = cs.OpenConnection()) { using (var command = connection.CreateCommand(sql)) { var table = command.GetSchemaTable(); return(table.ReadProxies <SchemaTableRecord>()); } } }
public static void GenerateProxiesFromDb(string path, string @namespace, string connStr, IEnumerable <string> tableNames = null, IEnumerable <string> udttNames = null, string schema = "dbo") { var sqlConnStr = new SqlConnectionString(connStr); sqlConnStr.GenerateProxiesFromDb( tableNames ?? sqlConnStr.GetDbObjectNames(TableType.TableOrView, null, schema), udttNames ?? sqlConnStr.GetDbObjectNames(TableType.Udtt, null, schema), path, @namespace, schema ); }
public static void GenerateProxiesFromDb(string path, string @namespace, string connStr, string prefix = null, bool includeTablesAndViews = true, bool includeUdtts = true, string schema = "dbo") { var sqlConnStr = new SqlConnectionString(connStr); sqlConnStr.GenerateProxiesFromDb( includeTablesAndViews ? sqlConnStr.GetDbObjectNames(TableType.TableOrView, prefix, schema) : null, includeUdtts ? sqlConnStr.GetDbObjectNames(TableType.Udtt, prefix, schema) : null, path, @namespace, schema ); }
private static DataTable GetDataTable(this SqlConnectionString cs, string sql, DataTable dst = null) { var dataTable = dst ?? new DataTable(); using (var connection = cs.OpenConnection()) { using (var command = connection.CreateCommand(sql)) { using (var adapter = new SqlDataAdapter(command)) { adapter.Fill(dataTable); } return(dataTable); } } }
internal static IEnumerable <string> GetDbObjectNames(this SqlConnectionString sqlConnStr, TableType type, string prefix = null, string schema = null) { var clause = ""; if (!string.IsNullOrEmpty(prefix)) { clause = string.Format(GetNamesClauses[type], prefix); } if (!string.IsNullOrEmpty(schema)) { clause += string.Format(GetNamesSchemaClauses[type], schema); } var cmd = string.Format(GetNamesCommands[type], clause); return(sqlConnStr.GetDbObjectNames(cmd)); }
private static void GenerateProxiesFromDb(this SqlConnectionString sqlConnStr, IEnumerable <string> dbObjectNames, TableType type, string path, string @namespace, string schema) { if (dbObjectNames == null) { return; } foreach (var name in dbObjectNames) { var script = sqlConnStr .GetResultSchema(string.Format(GetEmptyDataCommands[type], schema, name))? .ToTypeTemplate(name, @namespace)? .Expand(); script?.SaveToFile(path ?? @namespace.Replace('.', '\\'), name + ".cs"); } }
private static void GenerateProxiesFromDb(this SqlConnectionString sqlConnStr, IEnumerable <string> tableNames, IEnumerable <string> udttNames, string path, string @namespace, string schema) { sqlConnStr.GenerateProxiesFromDb(tableNames, TableType.TableOrView, path, @namespace, schema); sqlConnStr.GenerateProxiesFromDb(udttNames, TableType.Udtt, path, @namespace, schema); }
private static IEnumerable <string> GetDbObjectNames(this SqlConnectionString sqlConnStr, string cmd) { var result = sqlConnStr.Get <StringWrapper>(cmd).Select(x => x.Value); return(result); }