磁盘数据库存储,最佳实践

发布于 2024-09-12 02:43:09 字数 405 浏览 11 评论 0原文

如果这个问题对你来说很常见,我很抱歉,我在这个网站上进行了快速搜索和一些谷歌搜索,但找不到令人满意的答案。

我的问题是这样的;

我现在只担任软件开发人员 3-4 年。这似乎是一个足够长的时间来回答这个问题,但是在我所有的时间里,我从来没有开发过不需要将数据存储的主体存储在在线数据库中的软件。然而这一次,我的最新开发仅要求将其数据仅存储到磁盘。

实际数据本身是轻量级的。在代码中,主要资产将是一个类,其中只有一些必须保留的基于字符串的属性。我最初的想法是简单的序列化。在应用程序关闭时,新资产将被简单地序列化并作为文件存储在磁盘上。我还认为,也许出于备份目的(或者如果它是序列化类的更好选择),XML 文件会更合适。

我想不出这两种方法有什么明显的缺点,正是这个事实促使我公开提出这个问题。根据我的经验,解决问题的方法几乎没有缺点。

If this question seems common to you, I apologise, I did a quick search around this site and a few google searches and could not find a satisfying answer.

My question is this;

I have only been a software developer for 3-4 years now. This may seem like a time long enough to answer this question myself however in all my time, I have never had to develop software where the main body of data-storage is not required to be in an on-line database. This time however, my latest development requires only for its data to be stored only to disk.

The actual data itself is light-weight. In-code the main asset will be a class with only a few, string based properties on it which must be persisted. My initial thoughts are on simple serialisation. On application close new assets are simply serialised and stored on disk as a file. I also though maybe for backup purposes (or if it is somehow a better option to a serialised class) an XML file would be appropriate.

I cannot think of any distinct disadvantages of either of these approaches, it is this fact which causes me to ask this question publicly. In my experience, there is rarely a solution to a problem which does not have it's downsides.

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

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

发布评论

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

评论(4

婴鹅 2024-09-19 02:43:09

序列化(二进制或 XML)适用于少量数据。这种方法的问题是当您获取大量数据(您可能需要查询)时。

如果您在Windows平台上并且需要合适的数据库,您可以使用Windows自带的嵌入式数据库引擎 - ESENT。它是 Exchange 和 RavenDB 的后备存储。

这里是它的 .NET 包装器库。

ManagedEsent 提供对 ESENT(Windows 原生的嵌入式数据库引擎)的托管访问。 ManagedEsent 使用 Microsoft Windows 中的 esent.dll,因此无需下载和安装额外的非托管二进制文件。

Serialization (binary or XML) is appropriate for a small amount of data. The problem with this approach is when you get large amounts of data (that you may need to query).

If you are on a windows platform and in need of a proper database, you can use the embedded database engine that comes with windows - ESENT. It is the backing store of Exchange and RavenDB.

Here are the .NET wrapper libraries for it.

ManagedEsent provides managed access to ESENT, the embeddable database engine native to Windows. ManagedEsent uses the esent.dll that is part of Microsoft Windows so there are no extra unmanaged binaries to download and install.

ι不睡觉的鱼゛ 2024-09-19 02:43:09

最轻量级的解决方案,当然是使用XML和序列化。其主要优点是它非常简单,需要很少的代码,并且可以使用文本编辑器轻松编辑。这样做的另一个优点是能够拥有多个文件,并且它们可以轻松地在 PC 之间传输。

这是一个很好的关于 XML 序列化的教程

但是,如果您的应用程序要大量读取、写入和更改数据,并且只有一个数据源,那么最好使用轻量级数据库。很多人喜欢SQLite,而我个人更喜欢火鸟.

请参阅此有关在 C# 中使用 SQLite 的问题,以及请参阅此处,了解有关在 .net 中使用 Firebird 的信息

The most lightweight solution, is of course to use XML and serialization. The main advantage of that is that it is very easy, requiring little code, and is easily editable using a text editor. The other advantage of this is being able to have multiple files, and they will be easy to transfer from PC to PC.

Here is a nice tutorial on XML serialization.

However, if your application is going to be reading, writing, and changing the data a lot, and there is only one source of data, it would be better to use a light-weight database. Many people like SQLite, while I personally prefer Firebird.

See this question for using SQLite with C#, and see here for information for using Firebird with .net.

生寂 2024-09-19 02:43:09

另一个嵌入式数据库选项是Sql Server Compact Edition。最新版本 是 v4,它似乎比以前的版本有了很大的改进。

它在功能上相当于使用 XML 文件、Access 数据库,甚至是纯文本文件,因为您不需要在运行应用程序的计算机上运行 Sql Server 服务或安装任何特殊的东西。

Another embedded database option is Sql Server Compact Edition. The latest version of this is v4 and it seems to be much improved over previous versions.

It's functionally equivalent to using an XML file, or an access database, or even a plain old text file, in that you don't need to have a Sql Server service running or install anything special on the machine that your application runs on.

江挽川 2024-09-19 02:43:09

我一直在一个项目中使用 Sqlite,它工作得很好,也很容易使用,但使用 Sqlite 时要记住的一件事是它被设计为在单用户环境中使用,所以如果你将它用作例如,您可能会发现网站后端的数据库在最轻微的负载下就会陷入困境。

查看以下 C# 包装器的链接:
http://sqlite.phxsoftware.com/

我还使用 NHibernate 和 NHibernate.Linq 与数据交互,您可以在此处获得两者兼容的版本: http://www.dennisdoomen.net/2009/07/nhibernate-210-ga-with-linq-and- Fluent.html

NHibernate.Linq 允许您使用那些漂亮的 Linq 查询语法在您的 Sqlite 数据库上:

var onePiece = from s in session.Linq() where s.Name == "One Piece" select s;

I've been using Sqlite in a project and it works very well and it's easy to use too, one thing to keep it mind when using Sqlite though is that it's designed to be used in a single user environment, so if you use it as the database for the backend of a website for instance you're likely to find that it'll struggle under the slightest of load..

Check out this link for the C# wrapper:
http://sqlite.phxsoftware.com/

I also use NHibernate and NHibernate.Linq to interact with the data, you can get a build of both which are compatible here: http://www.dennisdoomen.net/2009/07/nhibernate-210-ga-with-linq-and-fluent.html

NHibernate.Linq allows you to use those nice Linq query syntax on your Sqlite db:

var onePiece = from s in session.Linq() where s.Name == "One Piece" select s;

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