Subsonic 生成无主键的表

发布于 2024-08-18 13:53:46 字数 37 浏览 6 评论 0原文

我需要生成一个没有主键的表。表没有主键是绝对必要的。请帮忙。

I need to generate a table without primary key. Its absolutely neccessary that the table dosen't have primary key. Please help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

许久 2024-08-25 13:53:47

对于 SubSonic 来说,表中包含主键是绝对必要的:)

以下引用自 SubSonic 文档中关于约定的内容

主键

如果您想使用 SubSonic 访问您的表,您需要为您的表定义一个主键。这在任何情况下都是很好的做法,我们需要它来对您的表执行某些操作。如果您没有定义主键,则不会生成您的类。

如果您不相信我们,或者您认为这是一个愚蠢的惯例 - SubSonic 不适合您。

It is absolutely necessary for the SubSonic that table contains primary key:)

The following is quoted from the SubSonic docs on conventions:

Primary Keys

If you want to use SubSonic to access your table, you need to have a Primary Key defined for your table. This is good practice in every case and we need it to do certain things with your table. If you don't have a Primary Key defined, your class won't be generated.

If you don't believe us, or if you think this is a silly convention - SubSonic isn't for you.

还不是爱你 2024-08-25 13:53:47

有什么理由不能使用序列之类的东西吗?

class Something {
     private static final SEQUENCE seq = getDBsequence()

     @id
     private final long id = seq.newNumber();

     private final String whateverData;
}

编辑:我写这个的方式有点愚蠢,因为一旦你重新启动应用程序。你会得到重复的键..你应该使用数据库提供的序列。对此感到抱歉。

Is there any reason you cannot use something like sequences?

class Something {
     private static final SEQUENCE seq = getDBsequence()

     @id
     private final long id = seq.newNumber();

     private final String whateverData;
}

EDIT:The way I wrote this was kinda dumb because once you reboot the app. you'll get duplicate keys.. You should use a sequence provided by the DB. Sorry about that.

棒棒糖 2024-08-25 13:53:47

正如亚当指出的那样,这是不可能的。老实说,我想不出有什么情况(在 OLAP 之外)不能进行 PK。或者也许你陷入了遗留问题——我可以挖掘这一点。

正如您所指出的,您可以做的就是使用我们的查询器工具来解决这个问题,然后您可以将结果发送到List<>。更新应该以同样的方式工作 - 但不确定插入。

as Adam pointed out this isn't possible. To be honest I can't think of a situation (outside OLAP) where you can't have a PK. Or perhaps you're stuck in a legacy situation - I can dig that.

What you can do to get around it is, as you pointed out, use our querier tools and then you can send the results ToList<>. Updates should work the same way - not sure about inserts though.

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