SunSonic 3.0 ORM open-source framework learning, sunsonicorm

Source: Internet
Author: User

SunSonic 3.0 ORM open-source framework learning, sunsonicorm

Introduction to SubSonic 3.0

The SubSonic3.0 ORM framework was introduced to the series of C # frameworks (links here) developed by AllEmpty from scratch. The content of this article comes from AllEmpty.

SubSonic is an open source ORM framework. The author is Robe Conery, written in C. It includes a T4 template to quickly generate data layer entity classes, which is a practical and rapid development framework. Allows developers to splice SQL statements in principle and focus on the implementation of business logic. SubSonic 3.0 supports three databases: MsSql, MySql, and SQLite. The database is flexible and the generated SQL statements are automatically optimized. Although it is an ORM framework, however, there is not much performance loss. It is easy to use and is a great ORM development framework.

My personal experience in the use process is: one-time writing and lifelong use. Write the required functions in the T4 template, and use the powerful custom functions of the T4 template to quickly and accurately generate your own entity classes. You can query Select classes and object classes, support for LINQ, support for Aggregate functions, support for stored procedures, and use the Distinct keyword. (Some features are added to AllEmpty. I use his modified version ).

SubSonic 3.0 Configuration

Create a project (the download link for the entire solution is later in this article), reference SubSonic. Core and Castle. dll, and add the SubSonic folder. The file structure of the entire project is as follows:

Using System; using System. collections. generic; using System. data; using System. linq; using System. text; using SubSonic. linq. structure; using SubSonic. query; using System. web; using System. web. UI; using System. web. UI. webControls; using Solution. dataAccess. dataModel; namespace SubSonicTest {public partial class Test: System. web. UI. page {protected void Page_Load (object sender, EventArgs e) {// Add record var Branch = new Branch {DeptCode = SPs. p_Branch_GetMaxBranchDeptCode (2, 1 ). executeScalar () + "", Name = "Network Department", Comment = "Network Problem Solving center", ParentId = 1, Sort = 8, Depth = 2 }; // save to database branch1.Save (); // print out S PrintImpInfo ("record added successfully, added Id =" + branch1.Id ); // query the added record and modify var branchModel = Branch. singleOrDefault (x => x. comment = "Network Problem Solving Center"); branchModel. name = "after-sales service department"; branchModel. save (); // Delete the Branch record you just added. delete (x => x. comment = "Network Problem Solving Center"); if (Branch. exists (x => x. comment = "Network Problem Solving Center") {PrintImpInfo ("");} else {PrintImpInfo (" ");} // query all data in Branch var list = Branch. all (); foreach (var branch in list) {PrintImpInfo (string. format ("name = {0}, comment = {1}, add date = {2}", branch. name, branch. comment, branch. addDate. toString ("yyyy-MM-dd HH: mm: ss ")));} /// use the function attached to the class object to query PrintImpInfo ("Use the function query attached to the Class Object"); var braanchList = Branch. find (x => x. id> 0); foreach (var branch in braanchList) {PrintImpInfo (branch. id. toString (); PrintImpInfo (branch. name); PrintImpInfo (branch. addDate. toString ("yyyy-MM-dd HH: mm: ss");} PrintImpInfo ("----------------------"); // paging function, get 2nd page records (5 records per page) PrintImpInfo ("Get 2nd page records (5 records per page"); var il = Branch. getPaged ("Id Desc", 2, 4); foreach (var branch in il) {PrintImpInfo (branch. id. toString (); PrintImpInfo (branch. name); PrintImpInfo (branch. sort. toString (); PrintImpInfo (branch. depth. toString (); PrintImpInfo (branch. parentId. toString (); PrintImpInfo (branch. addDate. toString ("yyyy-MM-dd HH: mm: ss");} PrintImpInfo ("------------------------"); // using the database name + DB, you can directly call the aggregate function PrintImpInfo ("database name + DB can directly call the aggregate function"); var db = new SubSonicTestDB (); // average value PrintImpInfo ("average value" + db. avg <Position> (x => x. id ). where <Position> (x => x. id <12 ). executeScalar () + ""); // calculates the number of PrintImpInfo ("calculated quantity" + db. count <Position> (x => x. id ). executeScalar () + ""); // calculates the total PrintImpInfo ("total computing volume" + db. sum <Position> (x => x. id ). executeScalar () + ""); // maximum PrintImpInfo ("maximum" + db. max <Position> (x => x. id ). executeScalar () + ""); // minimum value PrintImpInfo ("minimum value" + db. min <Position> (x => x. id ). executeScalar () + ""); // method of calling Stored Procedure var obj = SPs. p_Branch_GetMaxBranchDeptCode (1, 0 ). executeScalar (); PrintImpInfo ("Stored Procedure Call obj =" + obj); // you can use PrintImpInfo ("Linq query method") to query PrintImpInfo "); var query = new Query <Branch> (db. provider); var posts = from p in query where p. deptCode. startsWith ("0101") select p; foreach (var branch in posts) {PrintImpInfo (branch. toString ();} query = db. getQuery <Branch> (); posts = from p in query where p. id> 3 & p. id <6 select p; foreach (var branch in posts) {PrintImpInfo (branch. toString ();} var newBranchList = query. toList <Branch> (); foreach (var branch in newBranchList) {PrintImpInfo (branch. toString ();} // The join query method of the Linq multi-Table Association (PrintImpInfo ("join query method of the Linq multi-Table Association"); var query1 = from B in Position. all () join p in Branch. all () on B. branch_Id equals p. id where p. deptCode = "0101" select p; foreach (var branch in query1) {PrintImpInfo (branch. toString ());}} /// <summary> /// print the information to the output window in Debug mode. /// </summary> /// <param name = "info"> </param> private void PrintImpInfo (string info) {System. diagnostics. debug. writeLine (info );}}}

Add breakpoint debugging (Debug is required) to output the printed content, as shown in the following figure (the shortcut key for opening the output window is Ctrl + Alt + O ):

Click here to download


Orgspringframeworkorm-305releasejar does not have any source code connection, java

Generally, a jar package conflict occurs during integration, or the version is incorrect. You should focus on solving these problems, especially jar package conflicts.

What is the Java open-source framework?

Spring Framework [Java Open-Source J2EE Framework]
Spring is a powerful framework that solves many common problems in J2EE development. Spring provides consistent methods for managing business objects and encourages injection of good habits of interface programming rather than class programming. Spring's architecture is based on the Inversion of Control container using the JavaBean attribute. However, this is only part of the complete picture: Spring is unique in the use of IoC containers as a complete solution to build a focus on all architecture layers. Spring provides a unique data access abstraction, including a simple and efficient JDBC framework, which greatly improves efficiency and reduces possible errors. Spring's Data Access architecture also integrates Hibernate and other O/R mapping solutions. Spring also provides a unique transaction management abstraction that provides a consistent programming model for various underlying transaction management technologies, such as JTA or JDBC transactions. Spring provides an AOP framework written in the standard Java language, which provides POJOs with declarative transaction management and other enterprise transactions-if you need to-implement your own aspects. This framework is powerful enough to allow applications to get rid of the complexity of ejbs and enjoy key services related to traditional ejbs. Spring also provides a powerful and flexible MVC Web framework that can be integrated with IoC containers. [SpringIDE: The next auxiliary development plug-in on the Eclipse platform ].
WebWork [Java open-source Web Framework]
Developed by OpenSymphony, WebWork is a pull-over MVC J2EE Web framework dedicated to componentization and code reuse. Currently, the latest version of WebWork is 2.1, and the predecessor of WebWork2.x is the WebWork developed by Rickard Oberg. However, WebWork has been split into two projects: Xwork1 and WebWork2. Xwork is concise, flexible, and powerful. It is implemented in a standard Command mode and completely isolated from the web layer. Xwork provides many core functions: interceptor, form attribute verification during runtime, type conversion, and powerful expression Language (OGNL-the Object Graph Notation Language ), ioC (Inversion of Control Inversion Control) containers. WebWork2 is built on Xwork to process HTTP responses and requests. WebWork2 uses ServletDispatcher to change the HTTP request to Action (business layer Action class), session (session) application (application) range ing, and request parameter ing. WebWork2 supports multi-view representation. JSP, Velocity, FreeMarker, JasperReports, and XML can be used in the view section. Added AJAX support in WebWork2.2, which is built on the basis of the DWR and Dojo frameworks. [EclipseWork: an Eclipse plug-in for WebWork-assisted development]
Struts [Java open-source Web Framework]
Struts is an MVC framework based on the Sun J2EE platform. It is mainly implemented using Servlet and JSP technologies. Because Struts can fully meet the needs of application development, it is easy to use and agile, and has received a lot of attention in the past year. Struts integrates Servlet, JSP, custom tags, and message resources into a unified framework. Developers do not need to code themselves to implement a full set of MVC patterns during development, it saves a lot of time, so Struts is a very good application framework. [Stru ...... remaining full text>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.