Community Page
- john-sheehan.com/blog Jump to website »
-
Subscribe -
Community
-
Top Commenters
-
Popular Threads
-
Recent Comments
- Hey John, congratulations -- and, you're welcome!
- How would you set this up to use multiple domains on the server in different iis sites?
- Alternatively, a small change made Wordpress'e original htaccess file if you can use: RewriteCond %{HTTP_HOST} !^(tuncay\.kinali\.net) [NC] RewriteCond %{HTTP_HOST} !^$ RewriteRule ^/(.*)$...
- I also think a killer app for Twitter isn't out there yet, is TweetDeck the best positioned to complete this vision?
- Perhaps a upcoming Google Wave application will do what you want..
Just Sayin' More Words
A blog by John Sheehan
In Part 1, I covered building a ControllerBase class to use with SubSonic 2.1âs new RepositoryRecord entity base class. In order to get the hybrid API (RepostoryRecord + Foreign Key lazy-loaded properties) I like, I had to make some changes to the code generation templates. Hereâ
... Continue reading »
2 months ago
I was generating code using your proposed template for Repository Pattern against Oracle database 10.
The problem that I faced was that when you use tbl.ForeighnKeys to get the list of the foreign tables, it was not not working. This was due to a problem in GetTableSchema in OracleDataProvider. To be more specific, in the implementation of GetTableSchema for OracleDataProvider, when columns are retrieved, ForeignKeys property is not initialized and foreignkey tables are not added into it. Thus, when code generation is being done, it cannot find foreignkey tables to make the properties for them in the generated code. I suggest modify the GetTableSchema to the following one:
public override TableSchema.Table GetTableSchema(string tableName, TableType tableType)
{
TableSchema.TableColumnCollection columns = new TableSchema.TableColumnCollection();
TableSchema.Table tbl = new TableSchema.Table(tableName, tableType, this);
//tbl.ClassName = Convention.ClassName(tableName);
//string sql = TABLE_COLUMN_SQL;
QueryCommand cmd = new QueryCommand(TABLE_COLUMN_SQL, Name);
cmd.AddParameter(TABLE_NAME_PARAMETER, tableName, DbType.AnsiString);
TableSchema.TableColumn column;
using(IDataReader rdr = DataService.GetReader(cmd))
{
//get information about both the table and it's columns
while(rdr.Read())
{
tbl.SchemaName = rdr["USER"].ToString();
column = new TableSchema.TableColumn(tbl);
column.ColumnName = rdr[OracleSchemaVariable.COLUMN_NAME].ToString();
string scale = rdr[OracleSchemaVariable.NUMBER_SCALE].ToString();
string precision = rdr[OracleSchemaVariable.NUMBER_PRECISION].ToString();
column.NumberScale = 0;
column.NumberPrecision = 0;
if(!String.IsNullOrEmpty(scale) && scale != "0")
column.NumberScale = int.Parse(scale);
if(!String.IsNullOrEmpty(precision) && precision != "0")
column.NumberPrecision = int.Parse(precision);
// column.DataType = GetDbType(rdr[OracleSchemaVariable.DATA_TYPE].ToString().ToLower());
column.DataType = GetDbTypeOracle(rdr[OracleSchemaVariable.DATA_TYPE].ToString().ToLower(), column.NumberScale, column.NumberPrecision);
column.AutoIncrement = false;
int maxLength;
int.TryParse(rdr[OracleSchemaVariable.MAX_LENGTH].ToString(), out maxLength);
column.MaxLength = maxLength;
column.IsNullable = Utility.IsMatch(rdr[OracleSchemaVariable.IS_NULLABLE].ToString(), "Y");
column.IsReadOnly = false;
columns.Add(column);
}
}
cmd.CommandSql = INDEX_SQL;
//cmd.AddParameter(TABLE_NAME_PARAMETER, tableName);
tbl.ForeignKeys = new TableSchema.ForeignKeyTableCollection();
using(IDataReader rdr = DataService.GetReader(cmd))
{
while(rdr.Read())
{
string colName = rdr[OracleSchemaVariable.COLUMN_NAME].ToString();
string constraintType = rdr[OracleSchemaVariable.CONSTRAINT_TYPE].ToString();
column = columns.GetColumn(colName);
if(constraintType == SqlSchemaVariable.PRIMARY_KEY)
column.IsPrimaryKey = true;
else if(constraintType == SqlSchemaVariable.FOREIGN_KEY)
column.IsForeignKey = true;
//HACK: Allow second pass naming adjust based on whether a column is keyed
column.ColumnName = column.ColumnName;
//Hamed
if (column.IsForeignKey)
{
TableSchema.ForeignKeyTable fkTable = new TableSchema.ForeignKeyTable(this);
TableSchema.Table ftbl = this.GetForeignKeyTable(column, tbl);
column.ForeignKeyTableName = ftbl.TableName;
fkTable.ColumnName = column.ColumnName;
fkTable.TableName = ftbl.TableName;
//not needed for now
//fkTable.PrimaryColumnName = drFK[i]["PK_Column"].ToString();
//fkTable.ForeignColumnName = drFK[i]["FK_Column"].ToString();
tbl.ForeignKeys.Add(fkTable);
}
}
rdr.Close();
}
if(columns.Count > 0)
{
tbl.Columns = columns;
return tbl;
}
return null;
}
2 months ago
http://code.google.com/p/subsonicproject for that issue.