The usage and configuration of the SubSonic2.2 framework.

Source: Internet
Author: User

The usage and configuration of the SubSonic2.2 framework.

Online. there are also a lot of. net ORM frameworks, but I think the framework configuration is very simple. There seem to be a lot of people using it in the past few years, and now it seems to be using less, as the official upgrade has now reached 3.0, and the T4 template is used to generate the code, the amount of code seems to be reduced. However, I felt that 2.2 was still relatively stable. Some netizens asked me how to use the framework a few days ago and asked me to sort it out. Let's stop talking nonsense. Let's take a look at how to configure and use it.

Step 1 configure web. config:

Add the SubSonic declaration code to the configSections node as follows:

    <configSections>        <section name="SubSonicService" type="SubSonic.SubSonicSection, SubSonic" allowDefinition="MachineToApplication" restartOnExternalChanges="true" requirePermission="false"/>    </configSections>    <appSettings/>

 

 

Directly connecting database files

    <connectionStrings>        <add name="SubSonicConn" connectionString="Data Source=127.0.0.1; Database=agebook; Integrated Security=true;User ID=sa;Password=sa;" providerName="System.Data.SqlClient"/>    </connectionStrings>

Configure the SubSonic service configuration under the configuration node in <configuration> as follows:

Do not forget to add <clear/>

First, let's take a look at the name.

ConnectionStringName = "SubSonicConn" indicates the connection name.

GeneratedNamespace = "MyTest". This parameter is optional, but you can only remember the corresponding class namespace name.

    <SubSonicService defaultProvider="SubSonicConn" enableTrace="false" templateDirectory="">        <providers>            <clear/>            <add name="SubSonicConn" type="SubSonic.SqlDataProvider, SubSonic" connectionStringName="SubSonicConn" generatedNamespace="MyTest" removeUnderscores="false"/>        </providers>    </SubSonicService>

 

OK, the configuration file is ready.

Next, enter SubSonic. dll.

Step 2: configure the code generation tool:

Click the tool option ==> select external tool ==> add ==> in the vs 2010 toolbar. The title can start at will, the name I used is MySubSonicTools ==> click-through command-based selection. Select the sonic.exe file in the subcommanderfile where subsonicis downloaded ==> parameter: generate/out ormclass. The initial directory is $ (ProjectDir ), select the "use command window" and "prompt input parameters" options, and click OK.

Out ormclass. Note that if you create a website program, you must put it in App_Code.

 

 

 

 

Click the MySubSonic button, and a pop-up window appears. Click OK to refresh the website. The generated folder ormclass will appear,

If there is no App_Code, move it to it.

In the agebook library, the related table usage classes, AllStructs. cs are the main controller files, and StoredProcedures. cs is the stored procedure-related classes. If your operation does not generate these related classes, it should be a problem with the database link string configuration. After checking, you can generate them again.

Step 3: SubSonic method call

After completing the preceding two steps, SubSonic configuration is complete. The SubSonic syntax is as follows:

Before use, you must first reference:

Using MyTest; // This is the name in our configuration file, that is, the namespace name of the generated class using SubSonic;

Load Page code

If (! IsPostBack) {// 1. add A_Admin ad = new A_Admin (); ad. name = "ttttt"; ad. password = "wwwwwwwwww"; ad. loginip = "127.0.0.1"; ad. save (); // 2. modify int updateallid = new Update (A_Admin.Schema ). set (A_Admin.Columns.Password ). failed to ("changed Password") // set the Field Password to "changed Password ". where (A_Admin.Columns.Id ). isdue to ("2 "). execute (); // Of course, there are other ways to modify it // A_Admin ad1 = new A_Admin (); // ad1.Id = 24; // ad1.Name = "ttttt "; // ad1.Password = "wwwwwwwwwwww"; // ad1.Loginip = "127.0.0.1"; // 3. delete // DB. delete (). from (A_Admin.Schema ). where (A_Admin.Columns.Id ). isvice to ("7 "). execute (); A_Admin.Delete (30); // batch Delete // Query q = A_Admin.Query (); // q. addWhere (A_Admin.Columns.Password, "wwwwwwwwww"); // q. queryType = QueryType. delete; // q. execute (); // either of the above two methods can be // 4. query this. gridView1.DataSource = DB. select (). from (A_Admin.Schema ). executeDataSet (). tables [0]; this. gridView1.DataBind ();}

The above code includes addition, deletion, modification, and query methods.

I think it is quite simple. It saves the trouble of configuring xml than other orm frameworks such as nhib.pdf.

In fact, no matter what ORM framework you use in development, you can use EF as well. And even put aside these frameworks

Download this demo: Click me


How do I specify the default value when configuring the hibernate configuration file using the ssh2 framework?

I don't know what the default value you are talking about. You can use P as an example for reference:
<? Xml version = "1.0" encoding = "UTF-8"?>
<Beans xmlns: xsi = "www.w3.org/2001/XMLSchema-instance"
Xmlns = "www.springframework.org/schema/beans"
Xmlns: aop = "www.springframework.org/schema/aop"
Xmlns: tx = "www.springframework.org/schema/tx"
Xsi: schemaLocation = "www.springframework.org/schema/beans
Www.springframework.org/schema/beans/spring-beans-3.0.xsd
Www.springframework.org/schema/tx
Www.springframework.org/schema/tx/spring-tx-3.0.xsd
... The remaining full text>

How to configure struts and other frameworks in MyEclipse85? Do you need to change the webxml file and describe each step in detail?

Right-click the project and choose "MyEclipse". Click "Add Struts Capabilities ..."...
However, it is recommended that you do not use tools for configuration, which is too troublesome. After completing the configuration, you still need to modify a lot of things. Therefore, it is recommended that you manually configure the configurations, which may be a little difficult at the beginning, if you get more, you will feel great ~. ~

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.