管理无状态(Web)DB4O应用程序中的唯一ID

发布于 2024-08-31 18:13:25 字数 607 浏览 4 评论 0原文

我正在尝试使用 DB4O 构建一个新的 Web 应用程序 - 充满乐趣并且学到了一些非常有趣的东西。我正在努力解决的一件事是 DB4O 目前缺乏对无状态应用程序(即大多数 Web 应用程序)的支持以及对自动生成 ID 的需求。

我发现了许多富有创意且有趣的方法,挂钩 DB4O 的事件使用 GUID比数字 ID 或出于任何原因完全避免使用任何 ID 系统。

虽然每种方法都有其优点,但我想知道不太优雅的方法是否同样是最合适的。考虑下面的伪代码:

If ID == 0 or null
Set ID = (typeof(myObject)).Count
myObject.Save

这似乎是一个非常简单的方法,通常在这里我开始思考,“我错过了一些非常明显的东西”。我有吗?

I'm playing around with building a new web application using DB4O - piles of fun and some really interesting stuff learned. The one thing I'm struggling with is DB4O's current lack of support for stateless applications (i.e. web apps, mostly) and the need for automatically-generated IDs.

There are a number of creative and interesting approaches that I've been able to find that hook into DB4O's events, use GUIDs rather than numeric IDs or for whatever reason avoid using any system of ID at all.

While each approach has its merits, I'm wondering if the less-elegant approach might equally be the best fit. Consider the following pseudo-code:

If ID == 0 or null
Set ID = (typeof(myObject)).Count
myObject.Save

It seems like such a blindingly simple approach, it's usually about here that I start thinking, "I've missed something really obvious". Have I?

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

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

发布评论

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

评论(2

故事还在继续 2024-09-07 18:13:28

您需要在计数之前锁定 myObject 的插入和删除,直到保存之后

you need to lock inserts and deletes of myObject before the count to until after the save

爱要勇敢去追 2024-09-07 18:13:28

新的db4o-extras 项目包含 AutoIncrementID 支持插件。该项目刚刚开始,我还没有发布编译后的二进制文件。但它通过使用单个属性添加了对“身份”列或自动递增 ID 字段/属性的支持。

[AutoIncrement]
public property int ID {get; private set;}

[AutoIncrement]
protected int _id;
public property int ID {
  get{return _id;}
  set{this._id = value;}
}

The new db4o-extras project contains an AutoIncrementID support add-in. The project was just started, and I havn't yet posted a compiled binary. But it adds support for "Identity" columns or an auto-incremented ID field/property through the use of a single attribute.

[AutoIncrement]
public property int ID {get; private set;}

[AutoIncrement]
protected int _id;
public property int ID {
  get{return _id;}
  set{this._id = value;}
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文