.NET 数据存储 - 数据库与单个文件
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您又问了错误的问题:)
更好的问题是“如何构建一个允许我更改数据存储实现的应用程序?”
如果应用存储库模式并正确连接它,您可以构建可互换的持久层。因此,您可以从一种实现开始,然后根据需要更改它,而无需重新设计业务或应用程序层。
一旦您有了存储库接口,您就可以尝试多种不同方法的实现:
平面文件 - 您可以将数据保存为 XML,并且只要数据不是很多,您就可以存储完整的内容内存中(仅在启动时读取文件,在关闭时写入文件)。借助内存中的 XML,您可以获得非常高的吞吐量,而无需担心数据库索引等。
分布式数据库 - SQLite 或 SQL Compact 效果很好;它们提供了许多数据库优势,并且无需安装
本地数据库 - SQL Express 是轻量级数据库和全功能数据库之间的良好中间立场。如果小心使用,访问就足够了。主要好处是它包含在 MS Office 中(尽管默认情况下未安装),并且某些 IT 团队更愿意在计算机上安装 Access,而不是 SQL Express。
完整数据库 - MySql、SQL Server、PostGreSQL 等。
鉴于您的具体要求,我建议您使用基于 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
Pros
我的建议是使用 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.
在我看来,数据库 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!
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.
您可以免费获取 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.
数据库将是一个不错的选择。 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