views:

66

answers:

2

When saving a row that has a integere primary key following exception is thrown in the VB version: 'Public member 'ChangeTypeTo' on type 'Decimal' not found.'

This happens in ActiveRecord.VB file line 3406:

        Public Sub SetKeyValue(value As Object) Implements IActiveRecord.SetKeyValue
        If value IsNot Nothing AndAlso value IsNot DBNull.Value Then
            Dim settable = value.ChangeTypeTo(Of Integer)()

I can change the last line to:

Dim settable = CInt(value)  'value.ChangeTypeTo(Of Integer)()

This will fix the problem until I recompile the .tt files.

My question is, how can I change this in the ActiveRecord.tt file? The code in the tt file looks like this:

Dim settable = value.ChangeTypeTo(Of <#=tbl.PK.SysType#>)()

Any help is appreciated.

Thanks

A: 

The code generated is correct. You're trying to cast a decimal value as integer, this makes no sense. To edit the templates isn't the solution in this case, you need fix the logic of your application.

Apocatastasis
Thanks for answerig my question, however, I am not using any Decimals. The value is the Id that gets returned after an insert. The database (SQL 2005) defines the key as Int, the Subsonic activeRecord has the ID property as Integer, but in the Sub SetKeyValue (the Sub you can see in the code above) the value is a Decimal.Again, it inserts the record and when it returns the new ID (primary key) the exception happens.here is what I do in my code: Cust = New BV.bv_Customer copyTextboxesToCust() Cust.Save()Any hints what I may do wrong?Thanksgm
gm
A: 

I also had have various issues with the VB templates. That seems the focus of the Subsonic developers is in C#. Finally I choose to use the C# templates in another project, and reference it from my VB main application. The problem with the change that you're trying to do is that you're trying to replace a generic method for a concrete one, this isn't the better. <#=tbl.PK.SysType#> makes reference to the type of the primary key. If you only have integer primary keys, you can edit the template as Dim settable = CInt(value). Otherwise you need GetType for know the type of value, and then a select case with the apropiate conversion for each type that arrives to the method.

Apocatastasis
The intesting part of the wrong code, however, is that cast your integer primary key into Decimal. Why not search to back?
Apocatastasis
Thank you for your input. You were right, there seem to be issues with the VB templates. I did as you suggested, I added a C# class library project to my solution and used the C# templates. I changed my reference ( I had the VB templates also in a separate project) to the C# project and now it works perfectly.Thanks again.gm
gm