Remember, I published an article: Text Database --. in the future of the Net industry, more than a hundred comments are detonated, indicating that everyone is still interested in text databases.
After years of accumulation, we have already achieved some scale in text operations. Therefore, I would like to write this article to share it with you.
I. Code First:
1: Download CYQ. Data V5,: http://www.cyqdata.com/download/article-detail-426
2: extract a dll and add references to the project.
3: Since it is Code First, we can directly write the object class, for example:Public class Users: CYQ. data. orm. ormBase {public Users () {this. setInit (this, "Users", "Txt Path = {0}") ;}public int ID {get; set;} public string UserName {get; set ;} public string Password {get; set ;}}
Note two points:
1. inherited from OrmBase; 2. Specify the table name "Users" and database link in the constructor (Txt Path = {0 }).
Database Link Description ({0} indicates the root directory ):
Text Database (json storage): Txt Path = {0} Xml database (xml storage): Xml Path = {0} other databases, is the connection or configuration item of each database.
OK. Now you can add, delete, modify, and query operations. Let's talk about it here.
Ii. Code First Code example
1. Insert and update code and the following figure:
Code Description:
On the left side is the added and updated code, and on the right side is a simple example winform interface, which has two highlights.
1: Why do object classes use the using include operation?For text operations, the internal mechanism is in the memory and is written to the text only after Disponse is called. Therefore, using is used to call Disponse to write the operation to the file at the end.2: What is SetAutoParentControl?When the control name is named by constraint: it is a three-letter + attribute name, such as txtUserName and txtPassword, you can use the automatic value method. In this way, you can pull up N controls without changing the code. This is the form itself, and the orm will traverse the controls under the form for the value.
2: For other Orm functions, I will not go into details for the time being. The download contains api documentation instructions. Here, only interfaces are listed:
/// <Summary> /// public interface for Data Operations /// </summary> /// <typeparam name = "T"> </typeparam> internal interface ICommon: IDisposable {bool Insert (); bool Insert (InsertOp option); bool Insert (bool autoSetValue, InsertOp option );
Bool Update (); bool Update (object where, bool autoSetValue); bool Delete (object where ); bool Fill (object where); MDataTable Select (string where); MDataTable Select (int topN, object where); MDataTable Select (int pageIndex, int pageSize, string where, out int count); int GetCount (string where); bool Exists (string where); # region UI interface void GetFrom (object control); void GetFrom (object control, object value); bool GetFromJson (string jsonOrFileName); void SetAutoParentControl (object parent, params object [] otherParent); void SetAutoPrefix (string autoPrefix, params string [] otherPrefix ); void SetSelectColumns (params object [] columnNames); void SetTo (object control, object value, bool isControlEnabled); void SetTo (object control, object value ); void SetToAll (params object [] parentControls); # endregion string TableName {get; set ;}string DebugInfo {get ;}}
III. Basic instructions
1: Where does the table come from and where does the data store it?During initialization, the system automatically generates a table structure in the address directory based on the table name and link address based on the attribute name, and stores data in json or xml format.
2: where supports SQL?
Supported. However, for txt and xml, the most basic SQL parsing can be implemented with built-in functions>, >=, <, <=, =, is null, is not null, for basic queries such as like and order by, statements such as functions or group by are not supported.
3: application scenarios
Sometimes, the data is not big. It is too difficult to use access. It is not allowed to use sqlite server security settings. If you use mssql, you feel that you do not need to use the txt and xml commands.
Scenario 1: for example, if you write an object class in a simple configuration file, you can easily perform operations without having to create database tables.
Scenario 2: The purpose of Code First: When you need to quickly build the Code, you can directly use the txt file, and then the Business Code can be written, without waiting for the DBA to complete the database.
Later, you can change the web. config link to mssql, mysql, oracle, and other databases as needed. The Business Code remains unchanged.
Of course, this. SetInit (this, "Users", "Conn"); should be written in this way, corresponding to the Conn configuration item of webconfig.
Scenario 3: it is reasonable to directly operate txt for wp7 development.
4: multi-database compatibility
Used
CYQ. all Data friends know that it is very easy to support multiple databases. Now you can play txt and easily switch the link to other databases such as mssql, other databases are also compatible.
If you are interested, you can have fun and enjoy Code First !!!