SubSonic 3 中的选角问题

发布于 2024-08-20 14:30:35 字数 671 浏览 4 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

沉睡月亮 2024-08-27 14:30:35

我还遇到了 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 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.

治碍 2024-08-27 14:30:35

生成的代码是正确的。您试图将十进制值转换为整数,这是没有意义的。在这种情况下,编辑模板不是解决方案,您需要修复应用程序的逻辑。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文