Lightweight CYQ.Data passage opening presentation of the data layer (a)

Recently, write: Silverlight + WCF novice examples chess thematic index  series, nearly forty lengthy, written to have a sense of deranged!

Although forty end, from: Silverlight + WCF novice chess online demo instance  there is a short distance, but the overall framework and open source features are complete finished!

In order to avoid temporary obsessions, I had to write another series of articles about chess series of follow-up, before the first day to suspend smaller.

 

From the beginning to now, I feel it wrote four or five data framework, however memorable, or non-physical type frame when the first time to write! ! !

I remember in 2007, I published a: CyQ.Data lightweight data access layer [beta trial version]  [everyone was too young, the language a little excited, can not stand the pressure of the temporary closure of the article -_- .. .]

Two years later, when in 2009, opened a sealed two-year old text, while editing, maybe it is not the blog garden bug, change the date of the article, became a 2009 article!

At the same time he began to write the text of the open source: CYQ.Data lightweight road data layers (9)  [probably write too Wu Wu, the article is almost entirely copy the code word pitiful -_-......]

When written half falls on a business trip, months later came back and found not find find the original sample source code, so Wu Wu added something chapter, be a little bit end.

In recent days suddenly found on the computer of the original sample source code, run it and found that custom Table of bound list control have not been able to achieve -_-!

 

Today, it took hours N reconstruct the previous code, delete useless to re-cut, optimized code, adjusting the structure, back on the road, adhere to the road to finish! ! !

 

C 1. yQ.Data Introduction

 

DLL Download: Download  [size: 56K unencrypted did not confuse restriction, ease of use, can be directly used Reflector.exe view the source code, have continued on the back of open source article]

Class Library namespace introduced on the map:

General note:

05233818_O0Wa.gif
1: Table folder: custom implementations binding MDataTable, away from the DataTable
2: the Cache folder: a cache table structure information and
3: Action file folders: main operation target
4: SQL folder:
the DataType: providing C # data types and database types of conversion information
SQLHelper: I streamline database operations:
the Log: the data recording operation for the abnormality information
ProcedureSql :, query data table structure built query
outPutData: built sql 2000 and sql 2005 stored paging procedure; while providing helper class enumeration automatically generates the table or view

 

 

Reattachment Description:

Taken Row [Index] The present form of the access DLL principle, in order to facilitate knocking dot code, parameter passing enumeration method provides internal automatically converted to enumerate int, index access!

For this series, the reader try not to generate [+ entity classes reflecting a combination of query] type frame made relevant comparisons discussion!

 

Features are as follows:

l          support SQL Server 2000/2005/2008 .Net 2.0 . Other databases are not supported

l only need to configure a database link, for example:        

        < connectionStrings >
             < add  name ="Conn"  connectionString ="Server=.;database=CQSpace;uid=sa;pwd=123456" />
       </ connectionStrings >

     l          Easy to use, easy to use found in the following description.


 

ps: Since this adjustment amount of code, so I do not know what the problem would not change the current test the machine did not find the problem temporarily, if found bug please leave a message below.

 

C 2. yQ.Data instructions

 

The tool is based on the .NET 2.0 , it can not be used in .NET 1.1 project. First, give your project to add C yq.Data references can be!

Before beginning the project, please call the static method under Cyq.Data.SQL.OutPutData, paging stored procedure to generate the corresponding data such as:

05233818_O0Wa.gif
// generates a stored procedure with paging sql2005 Response.Write (CYQ.Data.SQL.OutPutData.GetSelectBaseOutPutToHtmlForSql2005 ()); // generates a stored procedure with paging sql2000 Response.Write (CYQ.Data.SQL.OutPutData.GetSelectBaseOutPutToHtmlForSql2000 () );


OutPutData then used to generate a database table or view enumeration:

05233818_O0Wa.gif
// After generating the enumeration, Copy the file to a class, [materialized required, because of the need relational database, the constructor does not pass parameters, Conn taken in default link] CYQ.Data.SQL.OutPutData Write  = new new  cyq. Data.SQL.OutPutData (); // output table enumeration Response.Write (write.OutPutAllTableEnum (CYQ.Data.SQL.OutPutData.TableType.U, CYQ.Data.SQL.OutPutData.FiledDescriptionType.NoDescription)); // enumeration output view Response.Write (write.OutPutAllTableEnum (CYQ.Data.SQL.OutPutData.TableType.V, CYQ.Data.SQL.OutPutData.FiledDescriptionType.NoDescription) );
 



Of course, there is also provided a method of generating a single table.

Then start the actual project, the following examples have been tested:

1: a single row is filled:

  MAction action  =   new  MAction(TableNames.CQ_Album);
  
if  (action.Fill( 1 ))
  {
      lbText.Text 
=  action.Data[CQ_Album.AlbumName].Value.ToString();
      action.Close();
  }

 

2: data update:

 MAction action  =   new  MAction(TableNames.CQ_Album);
 
if  (action.Fill( 1 ))
  {
       action.Data[CQ_Album.AlbumName].Value 
=  txtAlbumName.Text;
       action.Update();
       action.Close();
  }

 

Data Update Method Two:

 MAction action  =   new  MAction(TableNames.CQ_Album);
 action.Data[CQ_Album.AlbumName].Value 
=  txtAlbumName.Text;
 action.Update(
" id=1 " );
 action.Close();

 

3: Data Delete:

MAction action  =   new  MAction(TableNames.CQ_Album);
action.Delete(2);
action.Close();

 

Data Delete Method Two:

MAction action  =   new  MAction(TableNames.CQ_Album);
action.DeleteByWhere(
" id=2 " );
action.Close();

 

4: data query and binding:

Search:

MAction action  =   new  MAction(TableNames.CQ_Album);
gvTable.DataSource 
=  action.Select();
gvTable.DataBind();
action.Close();

 

Paging query:

 MAction action  =   new  MAction(TableNames.CQ_Album);
 
int  rowCount;
 gvTable.DataSource 
=  action.Select( 1 10 " id>10 " out  rowCount);
 gvTable.DataBind();
 action.Close();

 

5: multi-table how to get?

A: View mode, the multi-table queries into the database in the view, where a single table, and use the same;

B: Custom query such as:

05233818_O0Wa.gif
string  table  =   " (select A.*,B.Name from CQ_Album A left join CQ_UserInfo U on A.UserID=U.UserID) v " ;
MAction action 
=   new  MAction(table);
int  rowCount;
gvTable.DataSource 
=  action.Select( 1 10 " id>1 " out  rowCount);
gvTable.DataBind();
action.Close();

 Of course, you just put self-defined sql statement, all put aside unified management on the line, do not appear sql statement on the screen!

 

Additional:

GetFrom methods and the introduction of SetTo himself from the new Entity Framework, the next version of the transformation from the index Fu / values ​​of liberation, so stay tuned:

 

05233818_O0Wa.gif
// original index settings:   action.Data [CQ_Album.AlbumName] .Value  =  txtAlbumName.Text;   // later modified to:   action.GetFrom (txtAlbumName);   // original index reading:  txtAlbumName.Text = action.Data [ CQ_Album.AlbumName] .Value   // after modified to:   action.SetTo (txtAlbumName);  







 

 

OK, this begins to go beyond that, welcome reader comments!

Reproduced in: https: //my.oschina.net/secyaher/blog/274387

Guess you like

Origin blog.csdn.net/weixin_33973600/article/details/91966860