在 WPF 应用程序中本地保存数据的最佳方法是什么?

发布于 2024-08-09 09:33:24 字数 428 浏览 4 评论 0原文

我正在构建一些 WPF 应用程序来管理我的时间。我想节省一个日历日的项目工作时间。

所以我的问题是如何保存数据的最佳选择是什么?我想我可以使用 XML 文件、Access 数据库文件或者可能是一个属性。我想将数据保存在本地,因此在这种情况下不需要 SQL Server 操作。 :)

你觉得怎么样,该走哪条路?

I'm building some WPF application to manage my time. I'd like to save time spans for work time on project for a calendar day.

So my question is what's the best choice on how to save the data? I figured I could use an XML file, an Access database file or maybe a property. I´d like to save the data locally, so no SQL Server action in this case. :)

What do you think, which way to go?

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

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

发布评论

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

评论(4

苏别ゝ 2024-08-16 09:33:24

我会以纯形式或 .NET 友好的形式获取 SQLite (在 Google 中搜索 'sqlite . net' 会给你一些选择)。它具有超级便携性,而且在我看来,它比 SQL Server Compact 更容易设置和分发。

重要的是确保您没有与代码中的持久性机制耦合得太紧密,因此将来您可以轻松地替换您想要的任何存储策略。

I would grab SQLite either in its pure or a .NET-friendly form (doing a Google search for 'sqlite .net' will give you a few options there). It's super-portable and, in my opinion, easier to set up and distribute than SQL Server compact.

The important thing is to make sure you are not too tightly coupled to your persistence mechanism in your code, so in the future you could easily substitute any storage strategy you want.

日暮斜阳 2024-08-16 09:33:24

我知道您说没有 SQL Server,但我读到这意味着您不需要“服务器”,并且您希望将数据存储在客户端上。我还假设您可能不介意数据的某些可管理性。你知道,比如备份之类的事情。而且交易总是很好,因此您的数据可以保持一致。因此,虽然您可以使用 XML(请从您的脑海中消除所有关于 Access 的想法),但当问题已解决时,您最终会滚动自己的持久性。

因此,请查看免费的 SQL Server Compact 版本。它是轻量级的,设计用于在桌面或移动设备上运行,并且如果您的应用程序需要这样做,则可以轻松部署。所有常见的持久性框架都支持它。我有没有提到它是免费的(因为不需要任何费用)?

I know you said no SQL Server, but I am reading that to mean you want no "server", and you want to store your data on the client. I also assume you probably wouldn't mind some manageability of your data. You know, things like backup. And transactions are always nice, so your data can remain consistent. So, while you could use XML (please banish all thoughts of Access from your mind), you would end up rolling your own persistence, when this is a solved problem.

So, please check out the free SQL Server Compact edition. It is lightweight, designed to run on a desktop or mobile device, and is easily deployable if your app ever needs to do that. And all the common persistence frameworks support it. And have I mentioned it is free (as in costs nothing)?

薔薇婲 2024-08-16 09:33:24

我建议尽可能选择最简单的数据源,并对其进行适当的解耦,以便您稍后在弄清楚什么适合您的目的时可以放入一个新的、不同的数据源。为此,您可能会发现 XML 甚至纯文本之类的东西是最简单的可行方法。

确定数据源所需的特征后,根据您的实际使用情况,选择适当的后备存储。

我认为预先做出这一决定并不重要,因为这是一个个人项目,而不是商业项目。

I'd suggest picking the easiest datasource possible and decoupling it appropriately so that you can drop in a new, different datasource at a later time when you figure out what's appropriate for your purposes. To that end, you may find something like XML or even plaintext to be the simplest thing that could possibly work.

Once you determine the characteristics that you'll need from your datasource, based on your actual usage, choose the appropriate backing store.

I don't think it's critical to make this decision up front because this is a personal project, not a commercial one.

灼疼热情 2024-08-16 09:33:24

我过去使用过的一种非常简单的方法是您的“xml 文件”想法。只需创建一个描述您关心的数据的对象,然后将其序列化为 xml 即可。

格雷格(Greg)说确保您的数据源正确解耦,以便在您的需求发生变化时可以将其切换出来,这是绝对正确的。

One dead simple approach I've used in the past is your "xml file" idea. Simply create an object that describes the data you care about, and then serialize it to xml.

Greg is absolutely correct when he says make sure your datasource is decoupled properly so you can switch it out if your requirements change.

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