views:

440

answers:

3

I am struggling pulling a simple list of records from one table object and printing them out.

I have a table called [Acceptance] that has four fields, two of which allow nulls. Here is the ddl for the schema object:

CREATE TABLE [dbo].[Acceptance](
    [AcceptanceID] [int] IDENTITY(1,1) NOT NULL,
    [AcceptanceCode] [nvarchar](2) NOT NULL,
    [AcceptanceDesc] [varchar](25) NOT NULL,
    [SortOrder] [tinyint] NOT NULL,
 CONSTRAINT [PK_Acceptance] PRIMARY KEY CLUSTERED 
(
    [AcceptanceID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

When I try to render a single field of a single record to the console using the following code:

var a = Acceptance.All();
            Console.WriteLine(a.First().AcceptanceID);
            Console.Read();

I get the following exception:

System.ArgumentException was unhandled Message="Object of type 'System.Byte' cannot be converted to type 'System.Boolean'."

None of my fields are of type Bit/Boolean. I'm just not getting it...

Nullable types and Linq Query syntax are 2 topics that I am struggling with...

Any insight into how do this properly is greatly appreciated.

Thanks,

Josh

+1  A: 

What DB are you using? I'm going to guess MySQL... you can go into the T4s and change the way the system type is defined. For the default template that's SQLServer.tt, with MySQL its MySQL.tt. Just look for where we set tinyint - it's an ongoing issue (with me at least) with returning byte[] vs bool - set as needed.

Rob Conery
Rob, thanks for the info. I'll check that out. FYI, using MS SQL 2005.
joshblair
Rob,I altered the GetSysType method as below: case "tinyint": sysType= "int"; break;and the GetDbType method as below: case "tinyint": return DbType.Int16;and got past my issue. Does this look like the appropriate modifications?To update the model I delete the ActiveRecord.cs, COntect.cs, StoredProcedures.cs, and Structs.cs, then I exclude the _Generated folder, then Include the _Generated folder and the model is regeenerated. Is this the most effective way to regenerate the model?Thanks again. SubSonic is amazing.Josh
joshblair
I just got a fix sent to me today for this - I'll post it in the next 2 days. I'm long overdue for a release :). Yah that sounds weird...
Rob Conery
+1  A: 

Any chance that you are using SQL Server Migration Assistant 2005 for Access? By default, the migration wizard adds timestamp columns to all tables with a data type of "timestamp." I recall that this field caused an exception similar (if not the same) as the one you are reporting when using SubSonic 3. You can disable the creation of the timestamp column via Tools > Default Project Settings > Add timestamp columns > Never.

sparks
This is a new SQL 2005 database with no timestamp columns but thanks for the tip. I think I am all sorted and Rob's comment above helped out. Thanks again.
joshblair
A: 

I was getting this error as well and the fix above was not fixing my issue but the latest build from GitHub does the trick.

I hope there is a release soon to fix up all these loose ends.

coryT