简体   繁体   English

用C#保存数据

[英]Saving data in C#

I'm designing a banking system and I reached the step where I want to store the account's info so I can retrieve it easily when I close the system. 我正在设计一个银行系统,并且到达了要存储帐户信息的步骤,以便在关闭系统时可以轻松地检索它。

How can I store it? 如何储存? Should I use threads here or it is the time to use databases and linking the classes with a database? 我应该在这里使用线程,还是时候使用数据库并将类与数据库链接?

If you are designing a banking system, you need to have a thorough understanding of transactional integrity . 如果要设计银行系统,则需要对交易完整性有透彻的了解。

For example: 例如:

If you move money from one account to another, you do at least two steps 如果您将资金从一个帐户转移到另一个帐户,则至少要执行两个步骤

  1. Deduct money from one account 从一个账户中扣除钱
  2. Add that money to another account 将该钱添加到另一个帐户

It would be a very bad result if you completed Step 1 and then your program failed for some reason before completing Step 2. 如果您完成了步骤1,然后您的程序由于某种原因而失败,则在完成步骤2之前,这将是非常糟糕的结果。

Read about and fully understand transactions before proceeding. 在继续之前,请阅读并充分了解交易。

Having said that... 话说回来...

Entity Framework provides a nice level of abstraction for data storage and allows you to manage database transactions. 实体框架为数据存储提供了很好的抽象级别,并允许您管理数据库事务。 I suggest you look into that technology, along with how to use database transactions with Entity Framework . 我建议您研究该技术,以及如何在Entity Framework中使用数据库事务

Create a database in sql server or oracle... Use Entity framework for data manipulation. 在sql server或oracle中创建数据库。使用实体框架进行数据处理。 i will recommend you to create WCF service (which will do your all db transactions) and use that wcf service in your application. 我将建议您创建WCF服务(它将执行所有数据库事务)并在您的应用程序中使用该wcf服务。

If you wants to make your application better then i would suggest to use Dependency Injection (structuremap , ninject or any other such..) .. it will help you to make your code clean, maintainable and testable.. 如果您想使您的应用程序更好,那么我建议您使用依赖注入(structuremap,ninject或任何其他此类..)..它将帮助您使代码干净,可维护和可测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM