views:

102

answers:

1

There is a problem when the int is nullable on GetHashCode

At the point of GetHashCode on ActiveRecord.tt there is a need for a nullable check. Something like this.

<#      
    if(tbl.PK.SysType=="int" && !tbl.PK.Nullable ){
#>        
        public override int GetHashCode() {
            return this.<#=tbl.PK.CleanName #>;
        }        
<#      }#>

(update) This value can be come null on the Views. I have include the views using this code I found on inet.

const string TABLE_SQL=@"SELECT *
    FROM  INFORMATION_SCHEMA.TABLES
    WHERE TABLE_TYPE='BASE TABLE'
    union
    select Table_catalog, table_schema, table_name, 'View' table_type 
    from information_schema.views";

After that, this error appears.

A: 

SubSonic requires a primary key that is not null. You need to modify your view so it returns an Id column that is a non null Integer or Guid.

EDIT: You can add a non null primary key that'll work for SubSonic by changing your view as follows:

CREATE VIEW MyView AS
  SELECT NewID() AS Id, *
  FROM MyTable

The one drawback is that you won't get a consistent Id. If that's a problem you could replace NewID() with a value computed from the column but the drawback of that is the performance will be slower.

Adam
I will check to see if the views that have this problem can have a unique primary key - but I belive that the use of the views is critical and need a way to handle the way they are in subsonic3
Aristos
You may be able to simply enhance your view a little to get round this. I've edited the answer to add an example
Adam