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.

Aristos
  • 66,005
  • 16
  • 114
  • 150
  • Why would a primary key be nullable? – Adam Cooper Aug 20 '09 at 08:50
  • Because it is null on the views !. I have include not only the tables but the views also, using the code I found on Internet. 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"; By the way, the views is very Important ! – Aristos Aug 20 '09 at 14:08

1 Answers1

0

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 Cooper
  • 8,077
  • 2
  • 33
  • 51
  • 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 Aug 20 '09 at 18:26
  • 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 Cooper Aug 20 '09 at 19:13