Rapid business Development with C#+linq+sql

Source: Internet
Author: User

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

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.