.NET 数据存储 - 数据库与单个文件

发布于 2024-09-15 10:53:41 字数 500 浏览 7 评论 0原文

我有一个 C# 应用程序,允许一个用户输入有关客户和工作地点的信息。这些信息非常基本。

  • 客户:姓名、电话号码、地址、电子邮件、相关工作地点。
  • 工作地点:名称、地点。

这是该程序所需的规格。

  • 输入数据量没有限制。
  • 每个应用程序单个用户。没有并发活动或多个用户。
  • 允许将用户条目/数据导出到可以在应用程序/用户之间轻松共享的外部文件。
  • 允许用户查询根据客户信息/工作地点信息的不同组合来显示客户。
  • 永远不会在应用程序之外查看或操作数据。
  • 该程序几乎总是在运行,并最小化到任务栏。
  • 启动时间并不是很重要,但我希望查询速度相当快。

这一切似乎都将我引向数据库,但是是一个非常轻量级的数据库。但是我还需要它在数据存储方面没有限制。如果您同意我应该使用数据库,请告诉我什么最适合我的需求。如果您认为我不应该使用数据库,请就您认为最好的方式提出一些其他建议。

I have a C# application that allows one user to enter information about customers and job sites. The information is very basic.

  • Customer: Name, number, address, email, associated job site.
  • Job Site: Name, location.

Here are my specs I need for this program.

  • No limit on amount of data entered.
  • Single user per application. No concurrent activity or multiple users.
  • Allow user entries/data to be exported to an external file that can be easily shared between applications/users.
  • Allows for user queries to display customers based on different combinations of customer information/job site information.
  • The data will never be viewed or manipulated outside of the application.
  • The program will be running almost always, minimized to the task bar.
  • Startup time is not very important, however I would like the queries to be considerably fast.

This all seems to point me towards a database, but a very lightweight one. However I also need it to have no limitations as far as data storage. If you agree I should use a database, please let me know what would be best suited for my needs. If you don't think I should use a database, please make some other suggestions on what you think would be best.

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

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

发布评论

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

评论(6

一绘本一梦想 2024-09-22 10:53:41

您又问了错误的问题:)

更好的问题是“如何构建一个允许我更改数据存储实现的应用程序?”

如果应用存储库模式并正确连接它,您可以构建可互换的持久层。因此,您可以从一种实现开始,然后根据需要更改它,而无需重新设计业务或应用程序层。


一旦您有了存储库接口,您就可以尝试多种不同方法的实现:

平面文件 - 您可以将数据保存为 XML,并且只要数据不是很多,您就可以存储完整的内容内存中(仅在启动时读取文件,在关闭时写入文件)。借助内存中的 XML,您可以获得非常高的吞吐量,而无需担心数据库索引等。

分布式数据库 - SQLite 或 SQL Compact 效果很好;它们提供了许多数据库优势,并且无需安装

本地数据库 - SQL Express 是轻量级数据库和全功能数据库之间的良好中间立场。如果小心使用,访问就足够了。主要好处是它包含在 MS Office 中(尽管默认情况下未安装),并且某些 IT 团队更愿意在计算机上安装 Access,而不是 SQL Express。

完整数据库 - MySql、SQL Server、PostGreSQL 等。


鉴于您的具体要求,我建议您使用基于 XML 的平面文件 - 唯一的条件是您可以接受与文件大小直接相关的应用程序的内存使用情况(因为您的数据是文本,甚至由于 XML 的重量,这将需要大量条目变得非常大)。

以下是根据您的要求列出的优点/缺点:

缺点

  • 输入数据量没有限制。
    • 使用内存中 XML 意味着您的应用程序无法扩展。它可以轻松处理 10MB 的数据文件,100MB 应该不是问题(除非您的系统 RAM 不足),除此之外您必须认真地问“我能负担得起这么大的内存吗?”。

优点

  • 每个应用程序只有一个用户。没有并发活动或多个用户。
    • XML 可以读入内存并由进程(实际上是 AppDomain)保存。它非常适合并发性问题很小的单用户场景。
  • 允许将用户条目/数据导出到可以在应用程序/用户之间轻松共享的外部文件。
    • XML 非常适合导出,也可以轻松导入到 Excel、数据库等...
  • 允许用户查询,根据客户信息/工作地点信息的不同组合来显示客户。
    • Linq-to-XML 是您的朋友:D
  • 永远不会在应用程序之外查看或操作数据。
    • ...然后将其完全保留在内存中不会导致任何问题
  • 该程序几乎总是在运行,最小化到任务栏。
    • 因此在启动时加载 XML,并在关闭时写入是可以接受的(如果文件很大,可能需要一段时间)
  • 启动时间不是很重要,但是我希望查询速度相当快
    • 启动时读取 XML 的速度相对较慢;但当它加载到内存中时,它将很难被击败。任何给定的数据库都需要启动数据库引擎,进行互操作/跨进程/跨网络调用,从磁盘加载结果(如果引擎没有缓存)等等......

You're asking the wrong question again :)

The better question is "how do I build an application that lets me change the data storage implementation?"

If you apply the repository pattern and properly interface it you can build interchangable persistence layers. So you could start with one implementation and change it as-needed wihtout needing to re-engineer the business or application layers.


Once you have a repository interface you could try implementations in a lot of differnt approaches:

Flat File - You could persist the data as XML, and provided that it's not a lot of data you could store the full contents in-memory (just read the file at startup, write the file at shutdown). With in-memory XML you can get very high throughput without concern for database indexes, etc.

Distributable DB - SQLite or SQL Compact work great; they offer many DB benefits, and require no installation

Local DB - SQL Express is a good middle-ground between a lightweight and full-featured DB. Access, when used carefully, can suffice. The main benefit is that it's included with MS Office (although not installed by default), and some IT groups are more comfortable having Access installed on machines than SQL Express.

Full DB - MySql, SQL Server, PostGreSQL, et al.


Given your specific requirements I would advise you towards an XML-based flat file--with the only condition being that you are OK with the memory-usage of the application directly correlating to the size of the file (since your data is text, even with the weight of XML, this would take a lot of entries to become very large).

Here's the pros/cons--listed by your requirements:

Cons

  • No limit on amount of data entered.
    • using in-memory XML would mean your application would not scale. It could easily handle a 10MB data-file, 100MB shouldn't be an issue (unless your system is low on RAM), above that you have to seriously question "can I afford this much memory?".

Pros

  • Single user per application. No concurrent activity or multiple users.
    • XML can be read into memory and held by the process (AppDomain, really). It's perfectly suited for single-user scenarios where concurrency is a very narrow concern.
  • Allow user entries/data to be exported to an external file that can be easily shared between applications/users.
    • XML is perfect for exporting, and also easy to import to Excel, databases, etc...
  • Allows for user queries to display customers based on different combinations of customer information/job site information.
    • Linq-to-XML is your friend :D
  • The data will never be viewed or manipulated outside of the application.
    • ....then holding it entirely in-memory doesn't cause any issues
  • The program will be running almost always, minimized to the task bar.
    • so loading the XML at startup, and writing at shutdown will be acceptible (if the file is very large it could take a while)
  • Startup time is not very important, however I would like the queries to be considerably fast
    • Reading the XML would be relatively slow at startup; but when it's loaded in-memory it will be hard to beat. Any given DB will require that the DB engine be started, that interop/cross-process/cross-network calls be made, that the results be loaded from disk (if not cached by the engine), etc...
美人迟暮 2024-09-22 10:53:41

我的建议是使用 SQLite。您可以在这里找到它:http://sqlite.org/。您可以在这里找到 C# 包装版本: http://sqlite.phxsoftware.com/

SQLite 非常有用轻量级,并且对于如此轻量级的引擎来说具有一些非常强大的功能。您可以考虑的另一个选择是 Microsoft Access。

My suggestion would be to use SQLite. You can find it here: http://sqlite.org/. And you can find the C# wrapper version here: http://sqlite.phxsoftware.com/

SQLite is very lightweight and has some pretty powerful stuff for such a lightweight engine. Another option you can look into is Microsoft Access.

ぃ弥猫深巷。 2024-09-22 10:53:41

在我看来,数据库 100% 就是您所需要的。它提供数据存储、数据检索(包括查询)以及将数据导出为标准格式的能力(直接从数据库或通过您的应用程序)。

对于轻型数据库,我建议 SQLite(发音为“SQL Lite”;))。您可以通过 google 搜索有关如何设置它的教程,以及如何通过 C# 代码与其交互的教程。我还找到了对 this SQLite 的 C# 包装器的引用,它可能能够完成以下大部分工作你!

It sounds to me like a database is 100% what you need. It offers both the data storage, data retrieval (including queries) and the ability to export data to a standard format (either direct from the database, or through your application.)

For a light database, I suggest SQLite (pronounced 'SQL Lite' ;) ). You can google for tutorials on how to set it up, and then how to interface with it via your C# code. I also found a reference to this C# wrapper for SQLite, which may be able to do much of the work for you!

丑疤怪 2024-09-22 10:53:41

SQLite 怎么样? 听起来它很适合您的应用程序。

您可以使用 System.Data.SQLite 作为 .NET 包装器。

How about SQLite? It sounds like it is a good fit for your application.

You can use System.Data.SQLite as the .NET wrapper.

枯叶蝶 2024-09-22 10:53:41

您可以免费获取 SQL Server Express。我想说,问题不在于为什么要使用数据库,而在于为什么不应该使用数据库?此类问题正是数据库的用途,而 SQL Server 是一个非常强大且广泛使用的数据库,因此,如果您打算采用其他解决方案,需要提供一个充分的理由不会与数据库一起使用。

You can get SQL Server Express for free. I would say the question is not so much why should you use a database, more why shouldn't you? This type of problem is exactly what databases are for, and SQL Server is a very powerful and widely used database, so if you are going to go for some other solution you need to provide a good reason why you wouldn't go with a database.

独享拥抱 2024-09-22 10:53:41

数据库将是一个不错的选择。 SQLite 正如其他人提到的那样。

您还可以使用 SQL Server Express 的本地实例来利用与其他数据库的改进集成Microsoft 开发堆栈的一部分(因为您提到了 C#)。

第三个选项是文档数据库,例如 Raven,它可能适合您的数据声音。

编辑
第四种选择是尝试 Lightswitch 几天后测试版发布时。 (8-23-2010)
/编辑

数据存储(硬盘的空闲空间)总是存在限制。根据 wikipedia,SQL Express 限制为 SQL Server Express 2008 R2 为 10 GB

A database would be a good fit. SQLite is good as others have mentioned.

You could also use a local instance of SQL Server Express to take advantage of improved integration with other pieces of the Microsoft development stack (since you mention C#).

A third option is a document database like Raven which may fit from the sounds of your data.

edit
A fourth option would be to try Lightswitch when the beta comes out in a few days. (8-23-2010)
/edit

There is always going to be a limitation on data storage (the empty space of the hard disk). According to wikipedia, SQL Express is limited to 10 GB for SQL Server Express 2008 R2

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