Casting problem in SubSonic 3

孤街浪徒 提交于 2019-12-12 01:42:31

问题


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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/2210119/casting-problem-in-subsonic-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!