The productivity of the C # Desktop program is really high, and today we summarize how to use c#+linq+sql to quickly develop a new business system.
LINQ is Microsoft's official lightweight ORM tool that combines SQL to quickly generate entity classes, which can be quickly developed through LINQ operations.
1. Generate Entity classes:
For a database structure that already exists (SQL Server), you can use the VS-bring command-line tool to generate the entity class:
The SQLMetal tool can be used to quickly generate entity classes in C # for SQL Server databases, with specific parameters:
The/server parameter specifies the server name
The/database parameter specifies the database name
The/namespace parameter specifies the namespace of the generated code
The/code parameter specifies the generated code name
2. Operations on entity classes in C #:
1: /*
2: * Shifenzheng is the database entity class name, inherited from System.Data.Linq.DataContext
3: * When instantiated, the parameter is the connection string of the database.
4:
5: * /
6: new Shifenzheng (@ "Data source=chao-computer\mssqlserver_r2;i Nitial Catalog=shifenzheng; User Id=sa; password=123123123; ");
7:
8: public frmmain ()
9: {
Ten: InitializeComponent ();
One : }
:
: privatevoid Sbsearch_click (object sender, EventArgs e)
: {
:
: string strName = TeName.Text.Trim ();
: if (strname.length==0)
: {
: MessageBox.Show ("Please enter the query criteria!") ");
: return ;
: }
:
* / *
: * The LINQ statement returns system.linq.iqueryable<kf_search.tbl> { System.data.linq.dataquery<kf_search.tbl>} object.
: * This object can be accessed only through foreach.
: * So convert it to a list object as the data source for the table control.
: * /
: in db. TBLs
: where cc. Name = = StrName && cc. mobile!=""
: Select cc;
£ º var dataList = Kfer. ToList ();
:
Gridcontrol : //Set the data source for the object
: gcdetails.datasource = dataList;
: "Name";
: "Gender";
Panax notoginseng : "Mobile";
: "Ctfid";
: "EMail";
: "Address";
:
MessageBox.Show (" Total search for" +datalist.count+ "Records!) ");
: }
3, the result of the final realization:
Rapid business Development with C#+linq+sql