This is a demo snippet of the XML database I am developing. This project is currently incomplete and will be open-source when appropriate.
For more information about the database, see
Http://www.cnblogs.com/chenxizhang/archive/2009/08/08/1541888.html
Simply put, this is a database design that uses XML as the data access source. It is completely Based on. NET and XML technologies and uses the LINQ technology. In my summary, the database is XML + object-oriented.
- XML indicates that the storage format is XML.
- Object-oriented means that each table is mapped to a business entity (this entity can be very complex), and database operations are completely object-oriented, without the need for SQL syntax
- Complex queries can all be solved using the LINQ syntax. Because the database method returns the object type.
If you can operate a database like the following, isn't it a good choice? If you are interested in developing XML databases, please feel free to give me feedback and discuss them.
Using System; using System. collections. generic; using XMLDatabase; using DataEntities; using System. linq; namespace SampleApplication {class Program {static void Main (string [] args) {// insert 1000 orders for about 13 seconds, the volume is 615KB /// insert 2000th orders for about 41 seconds, the volume is 1229KB, // insert 3,000th orders for about 77 seconds, the volume is 1933KB //// TODO: optimization of insert, delete, and update should be considered. In these three cases, we should not load all the documents. Can we use XMLWriter TO Do This? // we should consider the SubmitChange method similar TO that in linq to SQL, one-time submission // after the design is improved, you do not need to insert 1000 orders for one second. This is cool Console. writeLine ("1: creating a Database"); using (Database db = Database. createInstance ("Northwind", "E: \ Temp") // create an XML database named Northwind under the E: \ Temp Directory {Console. writeLine ("\ t succeeded in creating a database"); # region creates several table consoles. writeLine ("2: creating a Table"); Table <Order> OrderTable = db. create <Order> ("Orders", new [] {"OrderID"}); Table <Customer> CustomerTable = db. create <Customer> ("MERs", new [] {"CustomerID"}); Table <Employee> EmployeeTable = db. create <Employee> ("Employees", new [] {"EmployeeID"}); Console. writeLine ("\ t successfully created three tables"); # endregion # region insert record Console. writeLine ("3: insert record"); // insert an order record OrderTable. insert (new Order () {OrderID = 10248, CustomerID = "ABCDEF", OrderDate = DateTime. now, EmployeeID = 1, OrderItems = new List <OrderItem> () {new OrderItem () {OrderId = 10248, Quantity = 20, UnitPrice = 25, Product = new Product () {ProductId = 1, ProductName = "Apple" }}}); OrderTable. insert (new Order () {OrderID = 10249, CustomerID = "ABCDEF", OrderDate = DateTime. now, EmployeeID = 1, OrderItems = new List <OrderItem> () {new OrderItem () {OrderId = 10249, Quantity = 4, UnitPrice = 25, Product = new Product () {ProductId = 1, ProductName = "Pen" }}, new OrderItem () {OrderId = 10249, Quantity = 2000, UnitPrice = 2, Product = new Product () {ProductId = 1, ProductName = "Car" }}}); Console. writeLine ("\ t successfully inserted two order records"); // insert a customer record CustomerTable. insert (new Customer () {CustomerID = "ABCDEF", CompanyName = "Xizhang.com"}); Console. writeLine ("\ t successfully inserted a customer record"); EmployeeTable. insert (new Employee () {EmployeeID = 1, Name = "Chen xizhang", City = City. shanghai}); Console. writeLine ("\ t successfully inserted an employee record"); db. submitChanges (); // The Console takes effect in the database only after submission. writeLine ("\ t submitted database changes"); # endregion # region read records // the query here is the standard LINQ syntax // select the order Console with the order amount greater than 1000. writeLine ("4: Data query"); var query = from o in OrderTable. select () where o. orderItems. sum (d => d. quantity * d. unitPrice)> 1000 select o; foreach (var item in query) {Console. writeLine (item) ;}# endregion # region update record Console. writeLine ("5: update data"); var customer = CustomerTable. select (). where (c => c. customerID = "ABCDEF "). singleOrDefault (); Console. writeLine ("before \ t modification"); Console. writeLine (customer); // modify customer. companyName = "Microsoft.com"; CustomerTable. update (customer); db. submitChanges (); Console. writeLine ("\ t modified"); customer = CustomerTable. select (). where (c => c. customerID = "ABCDEF "). singleOrDefault (); Console. writeLine (customer); # endregion # region Delete record Console. writeLine ("6: delete record"); var order = OrderTable. select (). where (o => o. orderID = 10248 ). singleOrDefault (); Console. writeLine ("before \ t deletion"); Console. writeLine ("\ t" + order); OrderTable. delete (order); db. submitChanges (); Console. writeLine ("\ t deleted"); order = OrderTable. select (). where (o => o. orderID = 10248 ). singleOrDefault (); if (order = null) Console. writeLine ("\ t this order does not exist"); # endregion # region clear record Console. writeLine ("7: clear record"); // equivalent to DELETE * FROM... console. writeLine ("before \ t clearing"); var employee = EmployeeTable. select (). firstOrDefault (); Console. writeLine ("\ t" + employee); EmployeeTable. clear (); db. submitChanges (); employee = EmployeeTable. select (). firstOrDefault (); Console. writeLine ("\ t cleared"); if (employee = null) Console. writeLine ("\ t this employee does not exist"); # endregion # region Delete table Console. writeLine ("8: Delete table"); Console. writeLine ("before \ t deletion"); Console. writeLine ("\ t customer table existence: {0}", db. exists ("Customers"); db. drop ("Customers"); Console. writeLine ("\ t deleted"); Console. writeLine ("\ t customer table existence: {0}", db. exists ("Customers"); # endregion} Console. writeLine ("9: deleting a Database"); Database. deleteInstance ("Northwind", @ "E: \ Temp"); Console. read ();}}}
Author: Chen xizhang at 18:25:07
Published in: blog Park. For details, refer to the source.