SubSonic 3 中的选角问题
VB 版本中保存具有整数主键的行时会引发以下异常: “未找到类型‘Decimal’的公共成员‘ChangeTypeTo’。”
这种情况发生在 ActiveRecord.VB 文件第 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)()
我可以将最后一行更改为:
Dim settable = CInt(value) 'value.ChangeTypeTo(Of Integer)()
这将解决问题,直到我重新编译 .tt 文件。
我的问题是,如何在 ActiveRecord.tt 文件中更改此设置? tt 文件中的代码如下所示:
Dim settable = value.ChangeTypeTo(Of <#=tbl.PK.SysType#>)()
感谢任何帮助。
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我还遇到了 VB 模板的各种问题。 Subsonic 开发人员的重点似乎是 C#。最后,我选择在另一个项目中使用 C# 模板,并从我的 VB 主应用程序中引用它。您尝试进行的更改的问题在于您试图将通用方法替换为具体方法,这并不是更好。
<#=tbl.PK.SysType#>
引用主键的类型。如果您只有整数主键,则可以将模板编辑为Dim settable = CInt(value)
。否则,您需要 GetType 来了解value
的类型,然后使用select case
为到达该方法的每种类型进行适当的转换。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 asDim settable = CInt(value)
. Otherwise you need GetType for know the type ofvalue
, and then aselect case
with the apropiate conversion for each type that arrives to the method.生成的代码是正确的。您试图将十进制值转换为整数,这是没有意义的。在这种情况下,编辑模板不是解决方案,您需要修复应用程序的逻辑。
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.