BuddyJoe
BuddyJoe

Reputation: 71161

SubSonic 3 ActiveRecord Issues - Blank Data

When I examine the .Columns property of one of my business entities I had missing values for Table and PropertyName. I get the right count of records back from things like Take(5) but all 5 objects will be full of empty strings and 0 values.

Just tried it with another SQL connection and same thing? Where should I start troubleshooting this?

ADDITIONAL INFO and CODE:

// Replacing the CleanUp function seems to be cause
// What am I doing here that is not allowed?
// I'm dealing with Table names like USER_DETAILS and would prefer UserDetail  
// rename standard CleanUp to CleanUp2 then paste this into Settings.ttinclude
string CleanUp(string tableName)
{
    string res = tableName;
    //capitalization
    char[] ca = res.ToLower().ToCharArray();
    for (int i = 0; i < ca.Length; i++) {
      if ((i == 0) || (ca[i - 1] == '_')) {
            ca[i] = char.ToUpper(ca[i]);
      }         
    }
    res = new string(ca);
    //strip underlines
    res = res.Replace("_","");
    //strip blanks
    res = res.Replace(" ","");
    return res;
}  

SOLVED (sort of): Looks like it is the removal of the underlines that causes everything to go south. Rob, any chance this could work in a later version? I'd be glad to help if you could point me in the right direction in the source.

Upvotes: 1

Views: 616

Answers (4)

user200998
user200998

Reputation:

After running through the code base I think I've identified an easier solution (IMHO).

The IColumn interface has a 'PropertyName' property defined which I believe is designed to indicate the name of the property representing this column on the table class (akin to the 'ClassName' property on ITable). In the Structs.tt template this is not set so I have set it (circa line 39) to the value of the columns CleanName property.

This then allows the GetColumnByPropertyName method in DatabaseTable.cs (circa line 110) to use the PropertyName as opposed to using the Name.

I've added the Name property to the IColumn interface as it seemed to be an oversight, which then means that the Load extension method (Database.cs circa line 143) can be amended to access the Columns property of the passed in object (if it is a derivative of IActiveRecord) and use that to map the 'Name' to the 'PropertyName'.

If I can get the time to figure our GitHub I'll submit the changes.

Cheers

Gary

Upvotes: 0

Funky81
Funky81

Reputation: 1677

I've just applied your CleanUp function within my SubSonic3 Templates. It works just fine. But before do that, I made some patches within Subsonic Core to communicate between Subsonic objects and table column.

  • First, I tried to gather which columns that will be projected (ExecutionBuilder.cs - line 217) then add it into list of string
  • Pass that list into QueryCommand so the QueryCommand object knows which column that will be projected (ExecutionBuilder.cs - line 233)
  • Make some modification in DbQueryProvider.cs (line 297), so DataReader will pass list of column names
  • Finally DataReader will insert value from database according to order in list of string that passed before (Database.cs line 158)

You can look details what I'm doin in here.

Upvotes: 0

Jim W
Jim W

Reputation: 4970

Just to note, I think this is the same as issue #107 that I ran into last week. http://github.com/subsonic/SubSonic-3.0/issues#issue/107

Upvotes: 2

user1151
user1151

Reputation:

If you can post your CREATE sql for one of your tables - that would be a way to get started. Also - make sure you have primary keys, etc.

Upvotes: 2

Related Questions