Release a lightweight SQLSERVER data processing database DotNetSQL

Source: Internet
Author: User
DotNetSQL is a lightweight data processing encapsulation. It is recommended to be used as the project data persistence layer. It supports MSSQL20002005 and 2008 not tested. It can meet conventional data processing needs. It is suitable for Small and Medium-sized Projects Based on ASP. NET! It can help beginners improve development efficiency to a certain extent. DotNetSQL is mainly divided into the following modules DotNetSQL. Proc:

DotNetSQL is a lightweight data processing encapsulation. It is recommended to be used as the project data persistence layer. It supports MSSQL2000/2005,200 8 not tested. It can meet conventional data processing needs. It is suitable for Small and Medium-sized Projects Based on ASP. NET! It can help beginners improve development efficiency to a certain extent. DotNetSQL is mainly divided into the following modules DotNetSQL. Proc:

DotNetSQL is a lightweight data processing encapsulation. It is recommended to be used as the project data persistence layer. It supports MSSQL2000/2005,200 8 not tested. It can meet conventional data processing needs. It is suitable for Small and Medium-sized Projects Based on ASP. NET!

It can help beginners improve development efficiency to a certain extent.

DotNetSQL mainly consists of the following modules:

DotNetSQL. Proc: executes regular stored procedures, including the returned datatable, dataset, sqldatareader, return, output

DotNetSQL. SQL: Execute regular SQL statements and extract basic sqlhelper operations.

DotNetSQL. ORM. SQL: regular Model operations, insert, update, and delete Model

DotNetSQL. ORM. Proc: stored procedure-based model operations

DotNetSQL. Config: dynamic configuration (non-web. config), suitable for winForm

DotNetSQL. Cache: currently, only the stored procedure parameter name Cache is enabled, and no data Cache is available.

A few call examples are briefly listed:

1. General call of Stored Procedures


Create procedure [dbo]. [sp_Test]
@ A varchar (20 ),
@ B int,
@ C float,
@ D text,
@ E datetime,
@ F int output,
@ G varchar (20) output
AS
BEGIN
Set nocount on;
-- Logic processing code
END

This is a simple storage process, which is related to input parameters and output parameters. The following code is executed using DotNetSQL:

Code
Using DotNetSQL. Proc;

ExecuteProc ep = new ExecuteProc ();
Dictionary Out;
Int f;
String g;

Out = ep. RunProc ("sp_Test", "LiLei", 20, 32.3, "long text", DateTime. Now );

// Parameter description
// RunProc (stored procedure name, parameter a, parameter B, parameter c, parameter d, parameter e) No need to create a new SqlParameter object for each parameter

// Read output parameters
If (Out. ContainsKey ("@ f ")){
F = (int) Out ["@ f"];
}
If (Out. ContainsKey ("@ g ")){
G = Out ["@ g"]. ToString ();
}

In addition, there are multiple methods under ExecuteProc, such as no return values, DataTable, SqlDataReader, DataSet, and so on.

In addition, the performance comparison between using DotNetSQL to execute stored procedures and conventional ADO. NET operations.

The above test results are based on my small notebook. The error between the two is basically within 2 ms.

2. Data Operations Based on ORM

C # Code (Model class)
Using System;
Using DotNetSQL. ORM; // The namespace must be referenced.

[Property ("Member")] // sets the table name corresponding to this model.
Public class Member
{
Public Member ()
{
//
// TODO: add the constructor logic here
//
}

Private int _ id;
Private string _ name;
Private bool _ sex;
Private decimal _ money;
Private DateTime _ addtime;
Private string _ ext;

[Property (ColumnKeyType. PrimaryKeyAndIdentity)] // indicates that the Id column is the primary key of the table and is auto-incrementing.
Public int Id
{
Get {return _ id ;}
Set {_ id = value ;}
}

Public string Name
{
Get {return _ name ;}
Set {_ name = value ;}
}

Public bool Sex
{
Get {return _ sex ;}
Set {_ sex = value ;}
}

[Property (ColumnKeyType. ReadOnly)] // indicates that the column is read-only when processing data, that is, it is not modified.
Public decimal Money
{
Get {return _ money ;}
Set {_ money = value ;}
}

Public DateTime AddTime
{
Get {return _ addtime ;}
Set {_ addtime = value ;}
}
[Property (ColumnKeyType. Extend)] // indicates the extension column of the column. This attribute can be identified if this field does not exist in the database table.
Public string Ext
{
Get {return _ ext ;}
Set {_ ext = value ;}
}
}
// For more information about ColumnKeyType, see the documentation.

Note: The fields in the Model class must have the same names as those in the database table, including case sensitivity. We recommend that you use the code generator to generate a Model!

The DotNetSQL operation code is as follows:

Code
Member memberModel = new Member ();
ORMToSQL ormToSql = new ORMToSQL ();

// Obtain the object based on the primary key (Id.
MemberModel = ormToSql. GetModel (1); // obtain the data row with Id = 1 (entity)
If (memberModel! = Null ){
Response. Write (memberModel. Name );
}

// Insert a new entity to the database
MemberModel. Name = "sun. Lei ";
MemberModel. Sex = false;
MemberModel. Money = 45.46; // because the ReadOnly attribute is identified for this column in the model class, this column value is not inserted.
MemberModel. AddTime = DateTime. Now;

Int key = ormToSql. InsertModel (MemberModel); // insert data and return the auto-increment ID of the data.

// The update and delete operations are similar. In addition, the above methods have related overloading, such as updating the specified column. For details, refer to the document.

DotNetSQL also integrates stored procedure-based model operations.

DotNetSQL also integrates the basic operation methods in sqlhelper.

For details, see the document and click to download

If you are interested in DotNetSQL, you can ask for the source code from me! We also hope that DotNetSQL can help beginners achieve rapid development!

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.